C++ 重写CObList MFC的复制构造函数

C++ 重写CObList MFC的复制构造函数,c++,visual-studio,visual-c++,mfc,C++,Visual Studio,Visual C++,Mfc,我在MFC中工作,我有自己的模板类(CDFAObList),它是从CObList派生的,可以接受我自己的类(CDFAObject)的成员,它是从CObject派生的。我需要重写编译器为CDFAObList生成的复制构造函数,因为它最终会运行到具有私有复制和赋值函数的CObject,并提供以下功能: 1>error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' 1>

我在MFC中工作,我有自己的模板类(CDFAObList),它是从CObList派生的,可以接受我自己的类(CDFAObject)的成员,它是从CObject派生的。我需要重写编译器为CDFAObList生成的复制构造函数,因为它最终会运行到具有私有复制和赋值函数的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
1>错误C4430:缺少类型说明符-假定为int。注意:C++不支持默认int
1> 请参阅正在编译的类模板实例化“CDFAObList”的参考
这是我的模板类:

#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;
};
#包括“DFAObject.h”
#包括“DFAManDoc.h”
#包括“DFAManTreeView.h”
模板类CDFAObList:公共CObList
{
公众:
CDFAObList(void){}
CDFAObList(CDDocument*pDoc、CTreeCtrl*pTree、xml_文档*pXmlDoc)
{
doc=pDoc;
树=树;
xmlDoc=pXmlDoc;
}
//问题副本构造函数
CDF义务人(施工CDF义务人和副本)
{
doc=toCopy.doc;
Tree=toCopy.Tree;
xmlDoc=toCopy.xmlDoc;
对于(int i=0;iGetSize();i++)
{
这个->添加头((T*)到拷贝->GetTail());
}
}
受保护的:
CDocument*doc;
CTreeCtrl*树;
xml_文档*xmlDoc;
};
我以前从未使用过类模板,所以我可能做了很多错事。提前感谢您的帮助。

应该

CDFAObList(const CDFAObList<T>& toCopy)
CDFAObList(const-CDFAObList&toCopy)
而不是

CDFAObList(const CDFAOblist<T>& toCopy)
CDFAObList(const-CDFAObList&toCopy)

谢谢!这几乎解决了我的问题,我只需将
上的
->
操作符也更改为
操作符:)