错误:对`bbque :: Event :: Event()'的未定义引用on ... / boost / serialization / access.hpp:132

时间:2015-08-20 10:04:01

标签: c++ boost-serialization

我使用boost v.1.55库来序列化/反序列化但是当我编译时我有这个错误。我是C ++编程和Boost库的新手。

event.h

    #ifndef BBQUE_EVENT_H_
    #define BBQUE_EVENT_H_

    #include <cstdint>
    #include <string>
    #include <ctime>
    #include <boost/serialization/access.hpp>

    namespace bbque 
    {
    class Event
    {

    public:

        Event();

        Event(std::string const & module, std::string const & type, const int & value);
        ~Event();

        inline std::string GetModule() const{
            return this->module;
        }

        inline std::string GetType() const{
            return this->type;
        }

        inline std::time_t GetTimestamp() const{
            return this->timestamp;
        }

        inline int GetValue() const{
            return this->value;
        }

        inline void SetTimestamp(std::time_t timestamp) {
            this->timestamp = timestamp;
        }

        inline void setValue(int v){
            this->value = v;
        }

        inline void setType(std::string t){
            this->type = t;
        }

        inline void setModule(std::string m){
            this->module = m;
        }

    private:

        friend class boost::serialization::access;
        template<class Archive>
        void serialize(Archive & ar, const unsigned int version)
        {
            if (version == 0 || version != 0)
            {
                ar & timestamp;
                ar & module;
                ar & type;
                ar & value;
            }
        }

        std::time_t timestamp;

        std::string module;

        std::string type;

        int value;
    };
    } //namespace bbque
    #endif // BBQUE_EVENT_H

event.cpp

#include "event.h"

using namespace bbque;

Event::Event(std::string const & module, std::string const & type, const int & value):

    timestamp(0),
    module(module),
    type(type),
    value(value) {

}

Event::~Event() {

}

access.hpp(错误行@new)

template<class T>
static void construct(T * t){
    // default is inplace invocation of default constructor
    // Note the :: before the placement new. Required if the
    // class doesn't have a class-specific placement new defined.
    ::new(t)T;
}

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

链接器错误表明您正在使用默认构造函数(并已声明它),但未在任何位置定义它。定义它(例如在event.cpp中或在event.h中内联),然后一切都应该没问题。