从 CObject 派生进行序列化会导致编译器访问错误
我创建了我的类 CData
并从 CObject
派生它,因为我需要序列化它。
class CData : public CObject
{
DECLARE_SERIAL(CData);
public:
CData();
virtual ~CData();
virtual void Serialize(CArchive& ar);
//Data
CString m_strName;
ULONG m_ulID;
CString m_strCorps;
CPoint m_Coordinate;
short m_sStatus;
};
我在文档类中使用了 vector
类型的向量。我在程序运行时使用 vecData.push_back(Data)(其中 Data 的类型为 CData)向向量添加新的 CData 对象。
但是当我尝试编译它时,我收到以下错误:
错误 C2248:“CObject::CObject”:无法访问私有成员 在“CObject”类中声明
我搜索了一下,发现它与 CObject 类不可复制或类似的东西有关!?!?...
有人知道如何解决这个问题吗?
I created my class CData
and derived it from CObject
, because I need to serialize it.
class CData : public CObject
{
DECLARE_SERIAL(CData);
public:
CData();
virtual ~CData();
virtual void Serialize(CArchive& ar);
//Data
CString m_strName;
ULONG m_ulID;
CString m_strCorps;
CPoint m_Coordinate;
short m_sStatus;
};
And I use a vector of type vector<CData>
in my document class. I add new CData-objects to the vector during the runtime of the program using vecData.push_back(Data)
(where Data is of type CData).
But when I try to compile this i get the following error:
error C2248: 'CObject::CObject' : cannot access private member
declared in class 'CObject'
I searched a bit and found out, that it has to do with the CObject-class to be non-copyable or something like this!?!?...
Does anyone know how to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CObject
将复制构造函数声明为private
,因此您需要自己为您的类实现复制构造函数(和赋值运算符重载)。CObject
构造函数文档说:我希望这有帮助!
CObject
declares the copy constructor asprivate
, so you need to implement the copy constructor (and assignment operator overload) for your class yourself. TheCObject
constructor documentation says:I hope this helps!
您是否碰巧忘记了 .cpp 文件中的
IMPLMENT_SERIAL
?Did you happen to forget
IMPLEMENT_SERIAL
in the .cpp-file?