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

时间:2014-01-08 13:22:40

标签: c++

我正在尝试创建一个处理来自服务器的消息的stomp客户端。 为了使用访问者访问的客户端我这样做。

我一直得到"未定义的引用'vtable for StompConnected' (以及扩展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);
}

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

请指教我

谢谢!

1 个答案:

答案 0 :(得分:4)

你错过了

的实现
virtual ~StompConnected();