Archived

This topic is now archived and is closed to further replies.

JoeDark

Quick generic class q

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites