tags:

views:

56

answers:

4

I am terrible at reading c++ errors, but obviously Unresolved External Symbol means the function I am using isn't defined. The error I am getting is...

1>WorldState.obj : error LNK2001: unresolved external symbol "public: class Brutal::GameObject * __thiscall Brutal::GameObjectManager::createObject<class Player>(class Ogre::Vector3,class Ogre::Quaternion,class Brutal::PropertyList,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$createObject@VPlayer@@@GameObjectManager@Brutal@@QAEPAVGameObject@1@VVector3@Ogre@@VQuaternion@4@VPropertyList@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\Brett\Desktop\Factions Online\build\release\client\client.exe : fatal error LNK1120: 1 unresolved externals

This doesn't make any sense as createObject is defined and even comes up appropriately in MSVC when I right click it and click "go to definition"

My code which calls it is...

Brutal::GameObjectManager::getSingletonPtr()->createObject<Player>(Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY);

So am I missing something silly?

A: 

It looks like you're not linking to the associated library. You've got the header included, so the compiler isn't complaining, but the linker doesn't know what you're talking about.

Tristan
A: 

Is createObject taking default arguements or is it overloaded ?

If so, are you defining all versions of that funtion ?

In the error message, its showing more parameters for function than in the call.

And If funtions is defined in some other library, you have to link it with your application by giving that library as input to Linker in Project settings.

bjskishore123
+2  A: 

Given that it is a template, have you put the implementation in a different file from the header? (You can do this for specific classes you decide to declare you have a template implementation for, known as instantiation).

I am going to extend my previous post as I can put in coding suggestions here more easily than in a comment.

You have a template function called createObject. You might consider "refactoring" this to use a class because it is easier to single this out.

This is sample code so fill in the detail to make it work for your exact example.

class GamePlayerManager
{
public:
   // all the other stuff
   template< typename T > createObject(/*params */)
   {
     // implement inline
       res = GameObjectFactory<T>::create(/* whatever parameters */);
   }
};

I have now singled out object creation into its own class called GameObjectFactory. At some point where Player is visible you can instantiate this template whilst hiding its create() method.

template class GameObjectFactory<Player>;

This is good enough for the compiler to know it needs to look in the implementation for the implementation of this class's functions (it promotes it into a "real" class so you can put the implementation into its .cpp file). Note that this is an instantiation, not a specialisation, so your template GameObjectFactory could still implement whatever functions you want to inline and you would not have to redefine them for your class. This is a good way to "reuse" the common code whilst allowing you to specialise on some of the detail.

CashCow
Yes, I have it seperated into a header and a cpp file. Here are both... http://ampaste.net/m4f697fc0 (GameObjectFactory.h) and http://ampaste.net/m25878ce5 (GameObjectFactory.cpp) Is it a problem seperating them like that?
Brett Powell
Forgot to mention I have the functions defined as so in GameObjectManager.cpp http://ampaste.net/m2f547dc1 (declared in seperate header as well)
Brett Powell
I have extended my solution because it was easier than typing it as a reply.
CashCow
+2  A: 

Since you are using a template function, it's definition has to be visible when you call it. Therefore, because this is a member function, it has to be implemented in the header where you declared it.

VJo
close. Either it must be implemented in the header where declared, or the particular template instantiation must be visible.
CashCow