Home >Backend Development >C++ >Why is my typedef in a base class template inaccessible in my derived class template?
Unrecognized Typedef in Derived Class Template
When declaring a derived class template B that inherits from a base class template A, it's expected that typedefs defined in A would be accessible within B. However, in the example provided, accessing Vec_t within B fails with an error that it's unrecognized.
According to the C Standard (14.6.2/3), in class template definitions and member definitions, unqualified name lookup does not extend to base classes that depend on template parameters. This means that unqualified access to typedefs defined in the base class is not permitted within the derived class template.
To resolve this issue, the full name of the typedef must be used within the derived class template. This can be achieved by explicitly specifying the base class scope as follows:
typename A<T>::Vec_t v;
By explicitly qualifying the name with the base class scope, the compiler can correctly resolve the reference to the Vec_t typedef defined in the base class template.
The above is the detailed content of Why is my typedef in a base class template inaccessible in my derived class template?. For more information, please follow other related articles on the PHP Chinese website!