我有一个函数,它返回一个 const& 对象。比方说,
class Y {
private:
Id id;
public:
Id const& GetId() const;
}
现在这个 Y 对象是另一个类的一部分,比方说 X 类,它需要通过 boost 序列化。
class X {
template <class Archive>
void serialize(Archive& ar, uint32 version)
{
ar & y->GetId();
}
Y y;
}
然而,boost 提示这个并给出错误:
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>'
C:\Users\Y.h(580) : see reference to function template instantiation 'Archive &boost::archive::detail::interface_iarchive<Archive>::operator &<const Id>(T &)' being compiled
with
[
如何序列化 Id?
最佳答案
ar & y->GetId();
应该是
ar & y.GetId();
关于c++ - C++如何从引用中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18386756/