在Boost序列化中,Boost::local_time::local_date_time给出错误
In Boost serialization, boost::local_time::local_date_time gives error
我正在尝试序列化MyData,但boost::local_time::local_date_time出现错误:"错误1错误C2512:'boost::local_time::local_date_time_base<>':没有合适的默认构造函数可用">
以下是代码:
//MyData.hpp文件
struct MyData
{
std::string id;
std::string name;
boost::local_time::local_date_time time;
private:
friend class boost::serialization::access;
template
void serialize(Archive &ar, const unsigned int version)
{
ar & id;
ar & name;
ar & time; // when i comment this line, error goes off
}
public:
MyData(void);
MyData(const parameter_strings & parms);
virtual ~MyData(void);
};
}
// MyData.cpp file
MyData::MyData(void)
{
}
MyData::~MyData(void)
{
}
MyData::MyData(const parameter_strings & parms)
{
// implementation aprt
}
BOOST_CLASS_EXPORT_IMPLEMENT(MyData(;BOOST_CLASS_Elementation(MyData,BOOST::serialization::object_serializable(;BOOST_CLASS_TRACKING(MyData,BOOST::serialization::track_selectly(;
请在这个话题上提供帮助,投入更多的时间,但到目前为止没有用。
我可以使用posix日期时间来获取当前日期和时间吗??或者我需要在哪里打电话给解释者询问日期时间??
感谢
文档状态:
boost::date_time库与boost::序列化库的文本和xml存档兼容。可序列化的类列表为:
boost::gregoriandate
date_duration
、date_period
、partial_date
、nth_day_of_week_in_month
,CCD_ 6 CCD_,first_day_of_week_before
、first_day_of_week_after
、greg_month
,greg_day
、greg_weekday
boost::posix_time
ptime
、time_duration
、time_period
所以,是的。但是您应该使用ptime
而不是local_date_time。
现在,首先,编译器抱怨它不知道如何初始化time
成员(因为它没有默认构造函数(。这与序列化无关:
struct Oops
{
boost::local_time::local_date_time time;
Oops() { }
};
已经有同样的问题了。修复它:
struct FixedOops
{
boost::local_time::local_date_time time;
FixedOops() : time(boost::local_time::not_a_date_time)
{
}
};
现在,开始序列化:
#include <boost/archive/text_oarchive.hpp>
#include <boost/date_time/posix_time/time_serialize.hpp>
#include <boost/date_time/local_time/local_time.hpp>
struct parameter_strings {};
struct MyData
{
std::string id;
std::string name;
boost::posix_time::ptime time;
private:
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & id;
ar & name;
ar & time; // when i comment this line, error goes off
}
public:
MyData() : time(boost::posix_time::not_a_date_time) { }
MyData(parameter_strings const&) : time(boost::posix_time::not_a_date_time) { }
virtual ~MyData() { };
};
int main()
{
boost::archive::text_oarchive oa(std::cout);
MyData data;
oa << data;
}
那就是
- 更改为
ptime
- 包括CCD_ 20的序列化报头
程序打印:
22 serialization::archive 10 0 0 0 0 0 0 0 0 15 not-a-date-time
查看Coliru直播
相关文章:
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- "local scope"中的 C++ 初始化静态变量
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- 在 /usr/local/lib 下找不到库
- C++:寻找"returning address of local variable..."的更正
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- 解析某些行的文本和输出"time of appearance"
- pip install uwsgi 失败,出现 /usr/local/include/string/string.h:7:10:致命错误:找不到'sstream'文件?
- 返回time()库函数的数据类型
- 如何将 time-uuid(存储在 boost uuid 中)转换为时间戳/自纪元以来的时间?
- 将 TensorFlow 链接到C++.Protobuf (/usr/local/include/google/prot
- 为什么我收到以下错误:"returning reference to temporary [-Werror=return-local-addr]"
- Visual Studio生成"Error: uninitialized local variable 'x' "而在线编译器不会 - 为什么?
- 如何从 boost::p osix_time::p time 获取秒数
- 调用 dll 函数时"Run-Time Check Failure #0 - The value of ESP"
- C++ SRAND(time(0)) 在猜谜游戏中不起作用
- 即使包含 <time.h 后仍"‘CLOCK_PER_SEC’ was not declared in this scope"错误>
- AppData\Local\Temp\cc59LXDc.o:test1.cpp: undefined reference to 'constructNewObjectOfClass
- C STD :: Local Time Daylight节省时间规则(DST)欧洲与美国人