Introduction / Context:
C++ supports generic programming through class templates. When you create a specific version of a template (an instantiation), you must supply the actual type argument(s). The correct placement and syntax of those type arguments is a core part of template usage and a frequent source of beginner mistakes.
Given Data / Assumptions:
- The language is standard C++ with template syntax.
- We are dealing with a class template, such as template class Box { }.
- Instantiation means writing a concrete type like Box or Box.
Concept / Approach:
- Class templates are named types that accept template parameters in angle brackets <...>.
- When instantiating, the concrete type parameter is written immediately after the generic class name, forming a template-id (e.g., Box).
- Keywords like template or class appear only in the template's declaration, not during ordinary instantiation in user code.
Step-by-Step Solution:
Consider template class Vector { }.To instantiate with int, you write: Vector v; The type 'int' follows the generic class name 'Vector' within < >.You do not write 'template' or 'class' at the use site; those belong to the template declaration.Therefore, the type used in an instantiation follows the generic class name.
Verification / Alternative check:
Check other examples: std::vector, std::map, std::unique_ptr. In each case, concrete types are placed directly after the template's name in angle brackets.
Why Other Options Are Wrong:
- the keyword template: Used in declarations or dependent-name contexts, not when simply instantiating a class template.
- the keyword class: Appears inside template parameter lists, not at the point of instantiation.
- the template definition: The definition is where the template is declared/implemented, not where it is instantiated.
- None of the above: Incorrect because the rule is exactly that the type follows the generic class name.
Common Pitfalls:
- Forgetting angle brackets or misplacing spaces that break parsing (e.g., >> vs > > in older standards).
- Confusing declaration-time syntax with use-site instantiation syntax.
Final Answer:
the generic class name
Discussion & Comments