Quick generic class q

Started by
2 comments, last by JoeDark 23 years, 2 months ago
The only reason I ask this question is that my reference book doesn't make mention of it. Can you only declare a generic class with a base class? i.e.
  
// --------------------------------------------------------------

template <class CType> class gen_class{};

class base {};

class derived : public base {};

int main()
{
   gen_class<derived> d_class;
}

// -------------------------------------------------------------

  
When I try to do this the compiler(DJGPP) says: type 'derived' is not a base type for type 'base' Sounds to me like you can only use base classes.. Why must they make things so difficult? JoeDark Edited by - JoeDark on January 25, 2001 1:56:53 PM Edited by - JoeDark on January 25, 2001 1:58:30 PM
Advertisement
Works for me using VC6...

-Mike
Sounds like your compiler is broken...
Are you sure this is what causes the error?
Ok, I looked at it a bit closer, and it doesn't seem to complain about the actual declaration, it seems to give me that error regarding the member functions of the generic class.

Hmm.. I see what it's saying now. Thanks for you help.. turns out I was trying to put a base class into a derived pointer. Don't I feel stupid In that context the error makes perfect sense.

JoeDark

Edited by - JoeDark on January 26, 2001 2:13:33 PM

This topic is closed to new replies.

Advertisement