Skip to main content
GameDev.net gamedev.net
🔒 Locked

Template inheritance hell

Started by Ataru Nov 25, 2003 at 1:36 PM 5 replies 1.1k views
Original Post
Ataru
Ataru
I''m playing around with templates and inheritance but I am getting compile errors. Class A is defined as: template class A and class B is defined as class A : public B When I do this, the compiler complains "error C2955: ''A'' : use of class template requires template argument list. So I change my constructor/destructur from A::A and A::~A to A::A which gives linker errors. What is the proper way to do such a thing?
quant
quant
You want something like


template<typename T>
class a
{
...
};

class b : public a<int>
{
...
};
-keyboard
emilk
emilk
or

template<typename T>
class a
{
...
};

template<typename T>
class b : public a<T>
{
...
};

to inherit the "templateness"


[edited by - emilk on November 25, 2003 2:52:43 PM]
Ataru
Ataru
Sorry, I did what emilk did (I forgot to put the template<> stuff there, but it was exactly the way emilk wrote it.

But when I do that, I get compile errors for my constructors of A

"error C2955: ''A'' : use of class template requires template argument list"

That''s my problem.
Ataru
Ataru

#ifndef DATA_H
#define DATA_H

class C
{
public:
C();
virtual ~C();
int x;
};

template <class T> class A
{
public:
A();
virtual ~A();
};

class B : public A<C>
{
public:
B();
virtual ~B();
};

#endif



// tstCyc.cpp : Defines the entry point for the console application.

//


#include "stdafx.h"
#include "data.h"

C::C()
{
}

C::~C()
{
}

B::B()
{
}

B::~B()
{
}

A::A()
{
}

A::~A()
{
}

int main(int argc, char* argv[])
{
B *bb;
bb = new B();
return 0;
}


when I try to compile this I get
"error C2955: ''A'' : use of class template requires template argument list"

This is the problem I am running into. (This should be the clearest way of explaining it.)
Sneftel
Sneftel
You''re not defining your constructor and destructor for A correctly. Remember, in templated function definitions outside the class, you must redeclare the template.

template<class T>
A<T>::A() { }

template<class T>
A<T>::~A() { }



"Sneftel is correct, if rather vulgar." --Flarelocke

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.