Arvind Arvind - 1 month ago 7x
C++ Question

C++ - meaning of a statement combining typedef and typename

In a C++ header file, I am seeing this code:

typedef typename _Mybase::value_type value_type;

Now, as I understand, quoting from « C++ the Complete Reference » by Schildt.
can be substituted by keyword class, the second use of
is to inform the compiler that a name used in a template declaration is a type name rather than an object name.

Similarly, you can define new data type names by using the keyword
. You are not
actually creating a new data type, but rather defining a new name for an existing

However, can you explain exactly what is the meaning of the above line of code, where
are combined together. And what does the "
" in the statement imply?


typedef is defining a new type for use in your code, like a shorthand.

typedef typename _MyBase::value_type value_type;
value_type v;
//use v

typename here is letting the compiler know that value_type is a type and not an object inside of _MyBase.

the :: is the scope of the type. It is kind of like "is in" so value_type "is in" _MyBase. or can also be thought of as contains.