C++ Dependent Name
In C++, a dependent name refers to a name (e.g., a type, variable, function, or template) whose meaning depends on a template parameter.
This concept arises in the context of templates, where the compiler cannot fully resolve certain names until the template is instantiated with specific types or values.
1. Introduction
When the compiler processes a template definition, it performs a two-phase lookup:
- Non-dependent names: Resolved at the point of template definition (when the template is written).
- Dependent names: Resolved at the point of template instantiation (when the template is used with concrete types).
Because dependent names rely on template parameters, the compiler delays their resolution until it knows the actual types involved. This introduces some special rules and syntax, like the typename
and template
keywords, to help the compiler distinguish between types and non-types or to access nested template members.
2. An all-in-one example
1 |
|
C++ Dependent Name