Archived

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

help with templates and inheritance

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites