错误:在 .../boost/serialization/access.hpp:132 上未定义对"bbque::Event::Event()"的引用
Error: undefined reference to `bbque::Event::Event()' on .../boost/serialization/access.hpp:132
我使用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;
}
如何解决这个问题?
链接器错误表明您正在使用默认构造函数(并且已经声明了它),但是没有在任何地方定义它。定义它(例如在event.cpp
或在event.h
内嵌),那么一切都应该没问题。
相关文章:
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- cl::Event::waitForEvents returns -7 (CL_EXEC_STATUS_ERROR_ F
- QT QPushButton Press Event
- mmap with /dev/input/event*
- 如何使用 epoll(void* event.data.ptr) 管理 Connection 的生命周期
- QGraphicsScene selectionChanged() event
- 为什么 event.mouseWheelScroll.delta 总是使用 SFML 返回 0
- OpenCL C++绑定:等待单个 cl::Event
- 类型 "void (Biometria::*)(char *idSensor, GRCAP_FINGER_EVENTS event)" 的参数与类型 "GRCAP_STATUS_EVENT_PROC
- 在/dev/input/event*中动态查找鼠标事件id
- wxwidgets Bind()项的计算结果不是在event.h中使用1个参数的函数
- wxWidgets Event-Propagation from Dialogs in C++
- WebSocket++, on_message event
- 项目 :错误 PRJ0019:工具从 "Performing Pre-Build Event..." 返回错误代码
- 用于线程"Wait for Alert/Event"的标准库版本
- SFML 2.1 C++文档-实际上是sf::Event的一个联合
- QObject::connect -- Event -- QFtp stateChange(int)
- 使用ios_base::register_callback()和ios_base::event检测流关闭
- 在Event Sourcing模式中,您是否有两个不同的类来读取和写入事件?
- 错误:在 .../boost/serialization/access.hpp:132 上未定义对"bbque::Event::Event()"的引用