• Create Account

## [fixed] Unresolved external symbol error; related to [virtual] inheritance?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Akashi  Members

Posted 17 September 2013 - 06:30 PM

I'm trying to work out a simple, functioning game engine, and I'm starting out as basic as I think I can get.

I have a virtual base class, Entity; the only child class I have for it currently is the Block class. I have a SceneManager class that contains a vector of Entity pointers, and with the Init() function, I attempt to populate it with Block objects, using an overloaded constructor. At first I thought it was because I did not have a corresponding overloaded constructor in the base class, but even when I added it, I got the same error:

-

LNK2019: unresolved external symbol "public: __thiscall Entity::Entity(void)" referenced in function "public: __thiscall Block::Block(short,short)"


-

This is my code:

Entity.hpp

Spoiler

Block.hpp

Spoiler

Block.cpp

Spoiler

SceneManager.cpp

Spoiler

### #2SiCrane  Moderators

Posted 17 September 2013 - 06:54 PM

You need to supply a body for your Entity constructor if you declare it in the class definition.

### #3Akashi  Members

Posted 17 September 2013 - 07:04 PM

If I insert

-

Entity::Entity():
ID (eIDBlock)
{
// empty for now
};


-

into the code, I get these errors:

-

LNK2005: "public: __thiscall Entity::Entity(void)" already defined in Block.obj (GamePlay.obj)
LNK2005: "public: __thiscall Entity::Entity(void)" already defined in Block.obj (SceneManager.obj)
LNK2005: "public: __thiscall Entity::Entity(void)" already defined in Block.obj (StateFactory.obj)


Edited by Akashi, 17 September 2013 - 07:04 PM.

### #4SiCrane  Moderators

Posted 17 September 2013 - 07:21 PM

Are you putting that in a header file? Function definitions in a header file need to be defined as inline. If you don't want to make it an inline function put the function definition in a source file.

### #5Akashi  Members

Posted 17 September 2013 - 07:56 PM

Oh, there we go. I thought I'd just do a quick fix and put the source in the header file, but now I've learned why that can mess things up.

Problem solved. Thanks!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.