OA. free
Free
MathWorks Quantitative Aptitude Quantitative Aptitude Medium

What is the purpose of the "typename" and "template" keywords in template parameters?

MathWorks aptitude question, verified with a worked answer. Free to practise - no sign-up.

What is the purpose of the "typename" and "template" keywords in template parameters?

Pick ONE option

Choose one option.
Show answer & explanation
Answer: A. "typename" is used to declare the template parameter and "template" is used to specify the template passed as a parameter.

In C++ template template parameters, the 'typename' keyword declares a type parameter, while the 'template' keyword is used to declare that the parameter itself is a template. This distinction is essential for correctly specifying template template parameters.

Step-by-step Derivation:
In C++, when declaring a template template parameter, the syntax is: template <template class Container> class MyClass. Here, 'typename' declares the inner type parameter T, and 'template' specifies that Container is itself a template being passed as a parameter. Therefore, 'typename' declares the template parameter, and 'template' specifies the template passed as a parameter.