|
-
August 7th, 2002, 12:33 PM
#1
Inheriting from a template class that has a pure virtual function
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."
-
August 7th, 2002, 12:47 PM
#2
I don't know if this answers your question, but it compiles:
Code:
template <class T> class baseclass
{
public:
virtual void purevirtualfunc() = 0;
T value;
};
class derivedclass : public baseclass<int>
{
virtual void purevirtualfunc()
{
value = 1;
}
};
Jeff
-
August 7th, 2002, 01:17 PM
#3
Or you could just do:
Code:
template <class T>
class baseclass
{
// whatever
};
template <class T>
class derivedclass : public baseclass<T>
{
// whatever
};
Last edited by Graham; August 7th, 2002 at 02:43 PM.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
August 7th, 2002, 01:25 PM
#4
Wow. Both solutions worked. Thanks a lot.
-
August 7th, 2002, 02:42 PM
#5
-
August 7th, 2002, 03:14 PM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|