我有两个类BaseTolerance和ImageProcessingTask。我收到错误消息:'错误C2228:左边的' .serialize'必须有class / struct / union'。
如果该行(在ImageProcessingTask中)
ar & make_nvp("ToleranceToMeasure", tolerance_to_measure_);
被注释掉,错误消息消失。
#include <boost/archive/xml_oarchive.hpp>
class BaseTolerance
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
using boost::serialization::make_nvp;
ar & make_nvp("ToleranceName", tolerance_name_);
}
char* tolerance_name_;
public:
BaseTolerance();
~BaseTolerance();
char* GetToleranceName();
void SetToleranceName(char* name);
};
和
#include "GeometricTolerance.h"
class ImageProcessingTask
{
BaseTolerance *tolerance_to_measure_;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
using boost::serialization::make_nvp;
ar & make_nvp("ToleranceToMeasure", tolerance_to_measure_);
}
public:
ImageProcessingTask();
~ImageProcessingTask();
BaseTolerance *GetToleranceToMeasure();
void SetToleranceToMeasure(BaseTolerance *tolerance);
};
答案 0 :(得分:1)
错误实际上来自于尝试序列化char *,一旦我看到它,我切换到std :: string,如Direct boost serialization to char array
中提出的那样