简体   繁体   English

覆盖CObList MFC的副本构造函数

[英]Overriding Copy Constructor for CObList MFC

I'm working in MFC, and I have my own templated class (CDFAObList) that is derived from CObList and can accept members of my own class (CDFAObject) that is derived from CObject. 我在MFC中工作,我有自己的模板类(CDFAObList),该模板类是从CObList派生的,可以接受我自己的类的成员(CDFAObject),该类是从CObject派生的。 I need to override the compiler-generated copy constructor for CDFAObList because it eventually works its way down to CObject, which has private copy and assignment functions and gives me this: 我需要重写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 &)'

It gives me the above errors even though I have the copy constructor overridden and the assignment operator overloaded in CDFAObject. 即使我在CDFAObject中重写了复制构造函数并且使赋值运算符重载,它也给了我以上错误。 But when I try to override the copy constructor for CDFAObList, I get the following compiler errors: 但是,当我尝试覆盖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

Here's my templated class: 这是我的模板化类:

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

I've never used class templates before, so I'm probably doing a bunch of things wrong. 我以前从未使用过类模板,所以我可能做错了很多事情。 Thanks in advance for your help. 在此先感谢您的帮助。

Should be 应该

CDFAObList(const CDFAObList<T>& toCopy)

instead of 代替

CDFAObList(const CDFAOblist<T>& toCopy)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM