Difficulty: Medium
Correct Answer: 3 (type parameters, non type value parameters and template template parameters).
Explanation:
Introduction / Context:
C++ templates are very flexible and allow several different kinds of entities to be passed as parameters. Understanding these categories helps when reading template declarations and designing generic libraries. This question asks how many kinds of entities can be used directly as template parameters in standard C++ and hints at the common classification by giving examples.
Given Data / Assumptions:
Concept / Approach:
There are three main categories of template parameters in C++. Type parameters represent a type, such as typename T. Non type parameters represent values of certain allowed types, such as integers or pointers, for example template<int N>. Template template parameters represent templates themselves, allowing you to pass container templates or other generic structures as arguments. These three categories cover the standard ways templates can be parameterised, and exam questions commonly ask you to recognise them and count them.
Step-by-Step Solution:
Step 1: List the known categories of template parameters: type, non type and template template parameters.Step 2: Count these categories, which gives the number three.Step 3: Option C explicitly states that there are 3 kinds and names them.Step 4: Option A and option B undercount the categories by ignoring at least one of them.Step 5: Option D and option E add unsupported categories such as namespaces or unspecified compiler extras, so option C is correct.
Verification / Alternative check:
If you look at template syntax examples from documentation, you will see patterns like template<typename T>, template<int N> and template<template<typename> class Container>. These examples illustrate type parameters, non type parameters and template template parameters respectively. There is no separate category for namespaces or arbitrary expressions as standalone parameter kinds, which confirms that three is the correct count.
Why Other Options Are Wrong:
Option A would only be correct if C++ supported type parameters and nothing else, which is not the case because non type parameters are widely used, for example in array bounds and compile time constants. Option B misses the template template parameter category. Option D incorrectly claims that namespaces themselves are template parameters, which is not supported by the language. Option E suggests compiler defined extra categories, but the question is clearly about the standard language rules.
Common Pitfalls:
Developers sometimes confuse non type template parameters with regular function parameters, forgetting that template parameters must be compile time constants of allowed types. Another pitfall is misunderstanding template template parameters and expecting them to be more flexible than they are. For exam purposes, remember the standard classification into three kinds of template parameters in C++.
Final Answer:
3 (type parameters, non type value parameters and template template parameters).
Discussion & Comments