The typename keyword.

Started by
2 comments, last by Brobanx 21 years, 6 months ago
I never really understood WHAT this keyword does, even after reading some technical info on MSDN. Can someone give me an example where typename actually resolves a name ambiguity?
Advertisement
template
struct SomeClass
{
typedef typename SomeConcept::someother_typedef special_type;
};
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Without typename, in MKH''s code above, the compiler will expect SomeConcept::someother_typedef to refer to a static member variable (default case). typename tells it it isn''t so.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Alright, that all makes sense now, thanks...

And as it turns out, even if a type is derived from a base class, you need to use the typename keyword when refering to that type...

I think this is a bug in GCC 3.2 i just found =/... (I'm deriving from the std::unary_function class, which has a typedef argument_type), when I use argument_type in my class, it says "implicit typename is deprecated", and if I add the typename keyword in front, it says its a parse error.. but it works properly if i say "typename unary_function::argument_type", but I shouldn't have to say it's from unary_function, because I'm deriving from it...

Is this actually a bug, should I report it to the GNU peeps?

[edited by - Brobanx on October 22, 2002 12:55:29 AM]

This topic is closed to new replies.

Advertisement