Possible Duplicate:
C++ difference of keywords 'typename' and 'class' in templates
I already know in many cases that class cannot be replaced by typename. I am only talking about the opposite: replacing typename by class.
Someone pointed out that only typename can be used here:
template<class param_t> class Foo 
{     
        typedef typename param_t::baz sub_t; 
};
But I do not see any problem replacing typename with class here (in MSVC).
To recap, can I ALWAYS replace typename with class? Please give an example if not.
No, you cannot always replace one with the other.
The two keywords typename and template are necessary for name disambiguation to inform the compiler whether a dependent name is a value (no keyword needed), a type (needs typename), or a template (needs template):
template <typename T> struct Foo
{
  char bar()
  {
    int x = T::zing;                 // value, no decoration for disambiguation of "T::zing"
    typedef typename T::bongo Type;  // typename, require disambiguation of "T::bongo"
    return T::template zip<Type>(x); // template, require disambiguation of "T::zip"
  }
};
Only the keywords typename and template work in those roles; you cannot replace either by anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With