【发布时间】:2011-02-14 13:31:30
【问题描述】:
我有两个类,一个继承自另一个。编译时出现以下错误:
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 unresolved externals
我真的不知道发生了什么.. 谁能看到我做错了什么?我正在使用 Visual C++ Express 2008。这是文件..
“include/Utility/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
“src/Utility/Parsables/Base.cpp”
#include "Utility/Parsables/Base.hpp"
namespace Utility
{
namespace Parsables
{
Base::Base( void )
{
}
Base::~Base( void )
{
}
}
}
“include/Utility/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
“src/Utility/Parsables/Entity.cpp”
#include "Utility/Parsables/Entity.hpp"
namespace Utility
{
namespace Parsables
{
Entity::Entity( void )
{
}
Entity::~Entity( void )
{
}
}
}
【问题讨论】:
-
项目中是否包含所有这些文件?你看到他们编译了吗?
-
是的,它们都包含在内并且可以正常编译。
-
尝试摆脱命名空间
-
只是 ac & p 的一个答案,我发布了一点:“我刚刚检查并记住了一些东西,我有两个文件都名为 Base.cpp,但它们位于不同的目录中。我看到一个编译,但不是两个。这可能是问题吗?”
-
@BLH 当然。首先要做的是确定你在链接什么。重命名任何可疑文件,并检查结果。
标签: c++ inheritance constructor destructor lnk2019