我有两个类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);
};
最佳答案
错误实际上来自尝试序列化char *,一旦我看到,我就按照Direct boost serialization to char array的建议切换到std::string。