0

我在 MFC 中工作,我有自己的模板类 (CDFAObList),它派生自 CObList,并且可以接受我自己的派生自 CObject 的类 (CDFAObject) 的成员。我需要覆盖 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

这是我的模板类:

#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;
};

我以前从未使用过类模板,所以我可能做错了很多事情。在此先感谢您的帮助。

4

1 回答 1

0

应该

CDFAObList(const CDFAObList<T>& toCopy)

代替

CDFAObList(const CDFAOblist<T>& toCopy)
于 2013-06-20T19:55:52.677 回答