Click to See Complete Forum and Search --> : Inheriting from a template class that has a pure virtual function


Brian Jones
August 7th, 2002, 12:33 PM
I was wondering what is the syntax, if there is any to inherit from a template class that has a pure virtual function

template <class base> class baseclass
{
void purevirtualfunc() =0;

int value;
};

class derivedclass : public "what is correct syntax?"
{
blah...
};

I have something like this in my program "class TestQueue : public Queue<QueueClass> Queue," but then I get "QueueQlass undeclared identifier."

jfaust
August 7th, 2002, 12:47 PM
I don't know if this answers your question, but it compiles:


template <class T> class baseclass
{
public:
virtual void purevirtualfunc() = 0;
T value;
};

class derivedclass : public baseclass<int>
{
virtual void purevirtualfunc()
{
value = 1;
}
};


Jeff

Graham
August 7th, 2002, 01:17 PM
Or you could just do:

template <class T>
class baseclass
{
// whatever
};

template <class T>
class derivedclass : public baseclass<T>
{
// whatever
};

Brian Jones
August 7th, 2002, 01:25 PM
Wow. Both solutions worked. Thanks a lot.

Graham
August 7th, 2002, 02:42 PM
Jeff: I'm not sure how to react to an expression of surprise that something we suggested worked! :) :mad: :confused:

jfaust
August 7th, 2002, 03:14 PM
Well, Brian did say thanks, so I choose to overlook the astonishment and take it as a compliment. And, hey, I'm still surprised my stuff works!

:) s,

Jeff