c++ - 无法编译 C++ 代码未定义对 `vtable 的引用

标签 c++

我正在尝试创建一个处理来自服务器的消息的 stomp 客户端。 为了做到这一点,我正在使用 Visitor-Visited 客户端。

我不断收到“对 StompConnected 的 vtable 的 undefined reference ” (以及扩展 StompServerFrame 的每个类)

这是代码:

////////////StompFrame.h//////////////

#ifndef STOMPFRAME_H_
#define STOMPFRAME_H_

#include <string>
#include <sstream>
#include <map>

using namespace std;

class StompFrame{
private:
    const string _command;
protected:
    map<string, string> _headers;
    string _content;
    StompFrame(string command);
public:
    static const char END_OF_MESSAGE = 0;
    string toString() const;
    void addHeader(string header, string value);
    bool getHeader(string header, string& value);
    void setContent(string content);
    ~StompFrame();
};



#endif

///////////StompServerFrame.h/////////////////

#ifndef STOMPSERVERFRAME_H_
#define STOMPSERVERFRAME_H_

#include "StompFrame.h"
#include "MessageProcessor.h"

class MessageProcessor;

class StompServerFrame: public StompFrame{
protected:
    StompServerFrame(string command);
public:
    virtual ~StompServerFrame();
    virtual void accept(MessageProcessor& processor) = 0;
};
#endif

/////////////StompConnected.h//////////////////

#ifndef STOMPCONNECTED_H_
#define STOMPCONNECTED_H_

#include "StompServerFrame.h"

class StompConnected: public StompServerFrame{
private:
    string _version;
public:
    static const string COMMAND_NAME;
    StompConnected(string version);
    virtual ~StompConnected();
    virtual void accept(MessageProcessor& processor);
};

#endif 

#ifndef MESSAGEPROCESSOR_H_
#define MESSAGEPROCESSOR_H_

class StompServerFrame;
class StompConnected;
class StompError;
class StompReceipt;
class StompMessage;

class MessageProcessor{
public:
    void processMessage(StompServerFrame* frame);
    void processMessage(StompConnected* frame);
    void processMessage(StompError* frame);
    void processMessage(StompReceipt* frame);
    void processMessage(StompMessage* frame);
};


#endif 

////////////////////////StompFrame.cpp///////////////////////////////

#include "../include/StompFrame.h"
#include <iostream>
#include <string>

using namespace std;

StompFrame::StompFrame(string command):_command(command), _headers(), _content(){}

StompFrame::~StompFrame(){}

string StompFrame::toString() const{
    stringstream stream;
    stream<<_command<<endl;
    for(map<string, string>::const_iterator iterator = _headers.begin(); iterator != _headers.end(); iterator++){
        string header = (*iterator).first;
        string value = (*iterator).second;
        stream<<header<<":"<<value<<endl;
    }
    stream<<endl;

    stream<<_content;
    if (_content != ""){
        stream<<endl;
    }
    stream<<END_OF_MESSAGE;

    return stream.str();
}

void StompFrame::addHeader(string header, string value){
    _headers[header] = value;
}

bool StompFrame::getHeader(string header, string& value){
    map<string, string>::iterator iterator = _headers.find(header);

    if (iterator == _headers.end()){
        return false;
    }

    value = (*iterator).second;
    return true;
}

void StompFrame::setContent(string content){
    _content = content;
}

////////////StompServerFrame.cpp///////////////

#include "../include/StompServerFrame.h"

StompServerFrame::StompServerFrame(string command):StompFrame(command){}

StompServerFrame::~StompServerFrame(){}

////////////////StompConnected.cpp/////////////////////

#include "../include/StompConnected.h"

StompConnected::StompConnected(string version): StompServerFrame(StompConnected::COMMAND_NAME),
    _version("version"){
    _headers[_version] = version;
}

void StompConnected::accept(MessageProcessor& processor){
    processor.processMessage(this);
}

const string StompConnected::COMMAND_NAME = "CONNECTED";

////////////////////MessageProcessor.cpp///////////////////

#include "../include/MessageProcessor.h"
#include "../include/StompServerFrame.h"
#include "../include/StompConnected.h"
#include "../include/StompError.h"
#include "../include/StompReceipt.h"
#include "../include/StompMessage.h"

void MessageProcessor::processMessage(StompServerFrame* frame){
    frame->accept(*this);
}

//////////////////////////////////////////////////////////////

请多多指教

谢谢!

最佳答案

你错过了

的实现
virtual ~StompConnected();

关于c++ - 无法编译 C++ 代码未定义对 `vtable 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20996928/

相关文章:

c++ - 定时 C++ 程序问题

C++ 结构动态内存分配

java - 如何通过Java输出控制台运行GDB并接受GDB命令?

c++ - vector 中的 Intrinsics Neon Swap 元素

c++ - 为什么 SetWindowsHookEx 返回 0?

c++ - 如何向 task.json 添加多个包含路径?

c++ - Flex和Bison生成C++头文件时如何使用m4?

c++ - #define 在模式之后有两个标记

c++ - 用于通用引用的左值/右值 -nes 编码

c++ - 从 std::istreambuf_iterator<> 复制到 std::vector<>