BLH*_*BLH 7 c++ inheritance constructor destructor lnk2019
我有两个类,一个继承自另一个.编译时,我收到以下错误:
Entity.obj:错误LNK2019:未解析的外部符号"public:__thiscall Utility :: Parsables :: Base :: Base(void)"(?? 0Base @ Parsables @ Utility @@ QAE @ XZ)在函数"public:__thiscall Utility"中引用:: Parsables :: Entity :: Entity(void)"(?? 0Entity @ Parsables @ Utility @@ QAE @ XZ)
Entity.obj:错误LNK2019:未解析的外部符号"public:virtual __thiscall Utility :: Parsables :: Base :: ~Base(void)"(?? 1Base @ Parsables @ Utility @@ UAE @ XZ)在函数"public"中引用: virtual __thiscall Utility :: Parsables :: Entity ::〜Entity(void)"(?? 1Entity @ Parsables @ Utility @@ UAE @ XZ)
D:\ Programming\Projects\Caffeine\Debug\Caffeine.exe:致命错误LNK1120:2个未解析的外部
我真的无法弄清楚发生了什么......谁能看到我做错了什么?我正在使用Visual C++ Express 2008.这是文件..
"包括/实用/ Parsables/Base.hpp"
#ifndef CAFFEINE_UTILITY_PARSABLES_BASE_HPP
#define CAFFEINE_UTILITY_PARSABLES_BASE_HPP
namespace Utility
{
namespace Parsables
{
class Base
{
public:
Base( void );
virtual ~Base( void );
};
}
}
#endif //CAFFEINE_UTILITY_PARSABLES_BASE_HPP
Run Code Online (Sandbox Code Playgroud)
"SRC /实用/ Parsables/Base.cpp"
#include "Utility/Parsables/Base.hpp"
namespace Utility
{
namespace Parsables
{
Base::Base( void )
{
}
Base::~Base( void )
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
"包括/实用/ Parsables/Entity.hpp"
#ifndef CAFFEINE_UTILITY_PARSABLES_ENTITY_HPP
#define CAFFEINE_UTILITY_PARSABLES_ENTITY_HPP
#include "Utility/Parsables/Base.hpp"
namespace Utility
{
namespace Parsables
{
class Entity : public Base
{
public:
Entity( void );
virtual ~Entity( void );
};
}
}
#endif //CAFFEINE_UTILITY_PARSABLES_ENTITY_HPP
Run Code Online (Sandbox Code Playgroud)
"SRC /实用/ Parsables/Entity.cpp"
#include "Utility/Parsables/Entity.hpp"
namespace Utility
{
namespace Parsables
{
Entity::Entity( void )
{
}
Entity::~Entity( void )
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
相关的是这个:
unresolved external symbol "public: __thiscall Utility::Parsables::Base::Base(void)"
Run Code Online (Sandbox Code Playgroud)
您需要为Base::Base和提供定义Base::~Base.声明不够好.即使你在任何一个函数中都没有任何关系,你需要保留一个空的函数体,因为C++实际上要求函数存在.C++将虚拟表维护等内容放在构造函数和析构函数中,因此即使你不需要在那里做任何事情也必须定义它们--C++必须在那里做事.
你确定Base.cpp被包含在构建中吗?