Error: undefined reference to `bbque::Event::Event()' on .../boost/serialization/access.hpp:132

Error: undefined reference to `bbque::Event::Event()' on .../boost/serialization/access.hpp:132

我正在使用 boost v.1.55 库 serialize/deserialize 但是当我编译时出现这个错误。我是 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;
}

我该如何解决这个问题?

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