简体   繁体   English

使用CArray时出错:无法访问在类CObject中声明的私有成员

[英]Error using CArray: cannot access private member declared in class CObject

I've created a dll using Microsoft Visual Studio 2010 and all works fine; 我已经使用Microsoft Visual Studio 2010创建了一个dll,并且一切正常。 now I want to add a member variable to the class I export; 现在我想在导出的类中添加一个成员变量; this member variable is a vector of struct which contains a CArray of another struct. 此成员变量是struct的向量,其中包含另一个struct的CArray。 The error I have in debug mode is 我在调试模式下出现的错误是

 error C2248: 'CObject::CObject': cannot access private member declared in class 'CObject' c:\\program files (x86)\\microsoft visual studio 10.0\\vc\\atlmfc\\include\\afxtempl.h 262 

I know I get this error because there a problem with the constructor of the struct which contains the CArray but I'm not able to fix it. 我知道我收到此错误,因为包含CArray的结构的构造函数存在问题,但我无法修复它。 Please help me. 请帮我。 Below I posted the code. 我在下面发布了代码。

EXPORTED CLASS: 出口舱:

namespace optFun
{
    // si posso definire altri casi in base a dove vengono collocati gli strumenti di gestione delle eccezioni
    enum RETURN{
        RETURN_INIT=0,
        RETURN_ERRORINREADING,
        RETURN_ERRORINPARALLEL,
        RETURN_ERRORINMAKESPAN,
        RETURN_SUCCESSFUL
    };

    struct DataPrescription{
    EDrug  NameDrug;
    float Dosage;
    EContainerType DestType;
    ELiquid IdDest;
    float CapacityDest;
    float Priority;
    bool ScaricoShaker;
    int  BlockNumber;

    DataPrescription(){
        NameDrug=EDrug_NoDrug;
        Dosage=0.0;
        DestType= EContainerType_Tot;
        IdDest=ELiquid_NoLiquid;
        CapacityDest=0.0;
        Priority=0.0;
        ScaricoShaker=true;
        BlockNumber=0;
    }

    DataPrescription(EDrug name,float dos,EContainerType dest,ELiquid ID,float cap_dest,float p,bool _ScaricoShaker,int _BlockNumber){
        NameDrug=name;
        Dosage=dos;
        DestType=dest;
        IdDest=ID;
        CapacityDest=cap_dest;
        Priority=p;
        ScaricoShaker=_ScaricoShaker;
        BlockNumber=_BlockNumber;
    }
};

struct final_block{

  CArray<DataPrescription> block_list;
  vector<load_info> carico;
  bool scarico_MI;
  final_block(){
      scarico_MI=false;
  }
};
    // This class is exported from the optFunDll.dll
    class OPTFUNDLL_API OptimizationTool
    {
    public: 
        // funzione che implementa il modulo di ottimizzazione
        CArray<DataPrescription> OptList;
        time_info time;
        vector<final_block> execution_mode;
        vector<state_info> StatusInfo;
        vector<load_info> LoadIndication;
        CArray<DataPrescription> ShakingList; //lista dei soli farmaci da restituire nell'ordine ottimo di schedulazione

        OptimizationTool(void);
        ~OptimizationTool();

        void CreateDataPrescription(vector<block>&);
        //void CreateBlockPrescription(block&); 
        RETURN scheduling(vector<string>,const char*,const char*,const char*);
        void InitializeParameter(double,int);
        void LoadDetails(vector<block>&,vector<magazzino_ospedale>&);
        //void ToLoad(ricetta&,vector<magazzino_ospedale>&,vector<magazzino_ospedale>&);
        void SyncronizeLoad(vector<block>&);

        // accessor function
        double get_PercVel();
        int get_CountSame();


    private:
        double _PercentMaximumVelocityOfSearchSpace; // % che determina range di variazione della velocità (e quindi anche della posizione)
        int _CountSame; // numero di stesse iterazioni dopo le quali la procedura di ottimizzazione si arresta


    };
}

The struct which give me error is "final_block"; 给我错误的结构是“ final_block”; I used this struct in this way: 我以这种方式使用此结构:

for(unsigned int i=0;i<output.size();i++){
           final_block pr;
           for(unsigned int j=0;j<output[i].list.size();j++){
               DataPrescription tmp(output[i].list[j].getID(),output[i].list[j].getdosage(),output[i].list[j].get_destination(),output[i].list[j].get_DestType(),output[i].list[j].get_CapacityDest(),output[i].list[j].getPriority(),output[i].list[j].processing_info.scarico_shaker,i+1);
               pr.block_list.Add(tmp);
           }
           pr.carico.push_back(this->LoadIndication[i]);
           pr.scarico_MI=output[i].scarico_MI;
          this->execution_mode.push_back(pr);
       }

Thanks in advance for your help. 在此先感谢您的帮助。

The problem is that MFC CArray (which derives from CObject ) is not copyable . 问题是MFC CArray (从CObject派生) 不可复制

So, the CArray data member inside your final_block structure makes the latter not copyable as well. 因此,您final_block结构中的CArray数据成员也使后者无法复制。

So, being not copyable, you can't push_back() instances of final_block in a std::vector . 因此,由于不可复制,因此不能在std::vector中使用final_block push_back()实例。

An option is to just substitute CArray with ** std::vector in your final_block structure. 一种选择是在final_block结构中final_block ** std::vector替换CArray

Or you can provide custom copy constructor and copy assignment for your final_block structure, and writing custom code for copying the CArray member. 或者,您可以为final_block结构提供自定义副本构造函数和副本分配,并编写用于复制CArray成员的自定义代码。

Frankly, I'd just use std::vector instead of CArray . 坦白说,我只是使用std::vector而不是CArray

暂无
暂无

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

相关问题 向CArray添加数据会产生错误“无法访问在类&#39;CObject&#39;中声明的私有成员” - Adding data to CArray gives error “cannot access private member declared in class 'CObject'” &#39;CObject :: CObject&#39;:无法访问在类&#39;CObject&#39;中声明的私有成员 - 'CObject::CObject' : cannot access private member declared in class 'CObject' 错误C2248:'CObject :: CObject':无法访问类'CObject'afxwin.h中声明的私有成员 - error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' afxwin.h 无法访问在类“ CObject”中声明的私有成员 - Cannot access private member declared in class 'CObject' 无法访问在类“ CObject”中声明的私有成员? - Cannot access private member declared in class 'CObject'? CPtrList 无法使用:错误 C2248:“CObject::operator =”:无法访问类“CObject”中声明的私有成员 - CPtrList cannot use: error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' VS2013编译器:“ CObject :: CObject”:无法访问在类“ CObject”中声明的私有成员 - VS2013 compiler: 'CObject::CObject' : cannot access private member declared in class 'CObject' 试图传递CStringArray给出错误无法访问类'CObject'中声明的私有成员 - Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject' 错误 C2248: 'CObject::CObject': 当我在 ZD7421054471AB272ZCEAC18FD97BBD237 - error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' when I calling hDC.SelectObject function in MFC &#39;CObject :: CObject&#39;:无法访问在&#39;CObject&#39;d:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ vc \\ atlmfc \\ include \\ afxcoll.h中声明的私有成员 - 'CObject::CObject' : cannot access private member declared in class 'CObject'd:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxcoll.h
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM