What is the Purpose of typename in C ?
When working with templates, it's possible to encounter perplexing error messages from the C compiler, gcc. In particular, correct declarations may cause bizarre compile errors that vanish when the typename keyword is applied. To clarify this issue, it's crucial to understand the role of typename.
According to Nicolai M. Josuttis's "The C Standard Library," typename specifies that the subsequent identifier is a type. Consider the following example:
template <class T> Class MyClass { typename T::SubType * ptr; ... };
In this example, typename clarifies that SubType is a type of class T. As a result, ptr is a pointer to the type T::SubType. Without typename, SubType would be interpreted as a static member, making T::SubType * ptr a multiplication of the SubType value of type T with ptr.
The above is the detailed content of What is the Purpose of the `typename` Keyword in C Templates?. For more information, please follow other related articles on the PHP Chinese website!