help with templates and inheritance

Started by
8 comments, last by kappa 20 years, 4 months ago
I got a couple of classes like this:

template<class T>
class CreateNewObject
{
public:
	T cmd;
	
};

class Object
{
 code...
}

class Ship : public Object
{
 code...
}
In main I now have this code CreateNewObject tship; but now I get a link error when trying to use code from the object class. What am I doing wrong?
Advertisement
Are you using VC++6, and is the link error C1001
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
You need to pass in the template parameter while declaring or instantiating the class object.

E.g.

CreateNewObject<Ship> newobject;


With passing the template parameter, the compiler is not going to generate the code for the CreateNewObject class. Hence, you get the linker error while trying the use the class / object
I meant to mean
"Without passing the template parameter, the compiler is not going to generate the code for the template class"
I think he knows that. If he is doing templates, I am sure he knows how they work.

The point I was trying to make, is Microsoft vc++6 has a very well known bug LInker error c1001.

There are ways to fix that, so that is why I asked.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
yes I have VC6++ and thats the error, how do I fix it?
I got sick of it, and finally got vc.net,

but here is the fixes.
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
no thats not it, my fault that was not the error it gave me.
Il post them

main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Object::DrawToScreen(void)" (?DrawToScreen@ Object@@QAEXXZ)
Debug/pong.exe : fatal error LNK1120: 1 unresolved externals

sorry again for wasting your time.
That means you declared a function prototype DrawToScene(); in class Object, but never declared the function body.

Simply put (in your Object cpp file)

void Object::DrawToScene(){} 
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
thx that was it.

This topic is closed to new replies.

Advertisement