获取参数化构造函数"undefined reference to `vtable`"错误



出现以下错误:

vtable的未定义引用

我无法找出根本原因。

我试着在谷歌上搜索,但仍然找不到原因。

代码如下:

IState.hpp→完整状态接口类

class IState {
public:
IState() = delete;
IState(ICallbacks &callbacks)
: m_callbacks(callbacks) {
}
virtual ~IState() = default;
IState(IState &state)
:m_callbacks(state.m_callbacks) {
};
IState& operator=(IState &state) {
this->m_callbacks = state.m_callbacks;
return *this;
};
IState(IState &&state) = delete;
IState& operator=(IState &&state) = delete;
bool operator== (const IState &state) {
return (this->state_id == state.state_id);
}
virtual const IError& stateEntry(ISubject &Subject) = 0;
virtual const IError& stateExit(ISubject &Subject) = 0;

private:
std::string state_id = std::string("");
ICallbacks& m_callbacks;
};

CState.hpp→接口类的部分实现

class CState : public IState {
public:
CState() = delete;
CState(ICallbacks &callbacks)
: IState(callbacks),
m_ccallbacks(static_cast<CCallbacks&>(callbacks)) {
}
virtual ~CState() {

};
CState(CState &state)
:IState(state),
m_ccallbacks(static_cast<CCallbacks&>(state.m_ccallbacks))  {
}
CState& operator=(CState &state) {
this->m_ccallbacks = static_cast<CCallbacks&>(state.m_ccallbacks);
return *this;
}
CState(CState &&state) = delete;
CState& operator=(CState &&state) = delete;
const IError& stateEntry(ISubject &Subject) override {
CSubject &cSubject = static_cast<CSubject&>(Subject);
return StateEntry(cSubject);
};
const IError& stateExit(ISubject &Subject) override {
CSubject &cSubject = static_cast<CSubject&>(Subject);
return StateExit(cSubject);
}
virtual const IError& StateEntry(CSubject &Subject) = 0;
virtual const IError& StateExit(CSubject &Subject) = 0;

private:
CCallbacks& m_ccallbacks;
};

ActiveState.hppCState.hpp的完全实现

class ActiveState : public CState {
public:
ActiveState() = delete;
ActiveState(ICallbacks &callbacks)
: CState(callbacks) {
}
ActiveState(ActiveState &state)
: CState(state) {
}
ActiveState& operator=(ActiveState &state) = default;
virtual ~ActiveState() {
}
const IError& StateEntry(CSubject &Subject) override {
return NO_ERROR;
};
const IError& StateExit(CSubject &Subject) override {
return NO_ERROR;
};
};

现在,每当我使用基类指针创建ActiveState对象时,它都会经过编译,但链接失败,并出现以下错误:

In function `ActiveState::ActiveState(ICallbacks&)':
File.cpp:(.text.11ActiveStateC2ERNS2_15ICallbacksE[_ZN611ActiveStateC5ERNS2_15ICallbacksE]+0x26): undefined reference to `vtable for ActiveState'

请让我知道我哪里做错了,以及如何解决这个问题。

抱歉,这是CMakeLists.txt的一个问题。CMakeLists.txt在GLOB中缺少ActiveState.cpp。因此出现了这个错误。谢谢你的帮助。

相关内容

  • 没有找到相关文章

最新更新