重写CObList MFC的复制构造函数
Overriding Copy Constructor for CObList MFC
我在MFC工作,我有我自己的模板类(CDFAObList),它是从CObList派生的,可以接受我自己的类(CDFAObject)的成员,它是从CObject派生的。我需要覆盖编译器为cdfaobist生成的复制构造函数,因为它最终会工作到CObject,它具有私有复制和赋值函数,并给我这个:
1>error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
1>see declaration of 'CObject::CObject'
1>see declaration of 'CObject'
1>This diagnostic occurred in the compiler generated function 'CObList::CObList(const CObList &)'
即使我在CDFAObject中重载了复制构造函数和赋值操作符,它也会给我上面的错误。但是,当我试图覆盖CDFAObList的复制构造函数时,我得到以下编译器错误:
1>error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>see reference to class template instantiation 'CDFAObList<T>' being compiled
这是我的模板类:
#include "DFAObject.h"
#include "DFAManDoc.h"
#include "DFAManTreeView.h"
template<class T> class CDFAObList : public CObList
{
public:
CDFAObList(void) { }
CDFAObList(CDocument* pDoc,CTreeCtrl* pTree, xml_document* pXmlDoc)
{
doc = pDoc;
Tree = pTree;
xmlDoc = pXmlDoc;
}
// problem copy constructor
CDFAObList(const CDFAOblist<T>& toCopy)
{
doc = toCopy.doc;
Tree = toCopy.tree;
xmlDoc = toCopy.xmlDoc;
for (int i = 0; i < toCopy->GetSize(); i++)
{
this->AddHead( (T*) toCopy->GetTail());
}
}
protected:
CDocument* doc;
CTreeCtrl* Tree;
xml_document* xmlDoc;
};
我以前从未使用过类模板,所以我可能做错了一堆事情。谢谢你的帮助。
应该是
CDFAObList(const CDFAObList<T>& toCopy)
代替
CDFAObList(const CDFAOblist<T>& toCopy)
相关文章:
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 当从函数参数中的临时值调用复制构造函数时
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 为什么需要复制构造函数,在哪些情况下它们非常有用
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 复制构造函数、赋值运算符C++
- std::ofstream 作为类成员删除复制构造函数?
- 复制构造函数C++无法正确复制指针
- 关于复制构造函数的一个棘手问题
- 为什么调用复制构造函数而不是移动构造函数?
- 填充上编译器生成的复制构造函数之间的不一致
- C++ 对象指针数组的复制构造函数
- C++ 基本 CTOR 说明 - 为什么不调用赋值/复制构造函数
- 防止在复制构造函数中隐式调用基构造函数
- 为用户定义的类正确调用复制构造函数/赋值运算符
- 具有已删除移动和复制构造函数的类的就地构造
- 复制构造函数隐式转换问题
- 复制构造函数中的递归调用