locked
CDialogEX vector of arrays -- CObject error trying to access private data RRS feed

  • Question

  • This may not be the right place for this, and I feel like this is something simple that I am completely missing (which irritates me).

     

    I created a dialog that inherits from CDialogEx. 

    vector<MyDialog *> dlgHolder;
    
    int count = x;
    
    for(int i = 0; i < count; i++)
    {
      MyDialog * temp = new MyDialog[7];
      dlgHolder.push_back(temp);
    }
    
    
    MyDialog * test = new MyDialog(var1, var2, var3, var4);
    
    //Error is with this part
    dlgHolder.at(index)[0] = test;
    
    //Actual error
    //error C2248: 'CObject::operator =' : cannot access private //member declared in class 'CObject'	
    
    

    I removed all the extra code. If I comment out that last line, the error goes away. Also, I tried setting test to the default constructor (the one without the variables), but the error still persists.

     

    Ideas? Suggestions?

    Thanks!

    Wednesday, April 20, 2011 2:23 AM

Answers

  • MyDialog * temp = new MyDialog[7];

    You have declared array of MyDialog with default constructor and push this array of objects to dlgHolder(Note: Not single object. Array of objects).

     

    dlgHolder.at(index)[0] = test;

    Have you overload operator = for MyDialog. If you don't overload = operator, it is trying to call base class operator. The CObject declared operator overloading = operator with private specifier.

     

    The following CObject class operator= taken from afx.h.

    private:
        CObject(const CObject& objectSrc);              // no implementation
        void operator=(const CObject& objectSrc);       // no implementation


    Thanks and Regards Selvam http://www15.brinkster.om/selvamselvam/
    • Marked as answer by Ctank02 Wednesday, April 20, 2011 1:45 PM
    Wednesday, April 20, 2011 4:39 AM

All replies

  • MyDialog * temp = new MyDialog[7];

    You have declared array of MyDialog with default constructor and push this array of objects to dlgHolder(Note: Not single object. Array of objects).

     

    dlgHolder.at(index)[0] = test;

    Have you overload operator = for MyDialog. If you don't overload = operator, it is trying to call base class operator. The CObject declared operator overloading = operator with private specifier.

     

    The following CObject class operator= taken from afx.h.

    private:
        CObject(const CObject& objectSrc);              // no implementation
        void operator=(const CObject& objectSrc);       // no implementation


    Thanks and Regards Selvam http://www15.brinkster.om/selvamselvam/
    • Marked as answer by Ctank02 Wednesday, April 20, 2011 1:45 PM
    Wednesday, April 20, 2011 4:39 AM
  • If you really want a vector of arrays, i.e. a ‘count x 7’ matrix, then consider this:

     

    std::vector< std::vector< MyDialog * > > dlgHolder;

    dlgHolder.resize(count);

    for(int i = 0; i < count; i++) dlgHolder[i].resize(7);

     

    Then you can access an element like this:

     

    dlgHolder.at(index)[0] = test;

     

    or

     

    dlgHolder[index][0] = test;

     

    You have to free with delete each unused dialog or use a helper class like ‘std::shared_ptr’.

     

    Wednesday, April 20, 2011 6:10 AM
  • Selvam, I actually knew that....It just didn't occur to me why it was behaving that way until your explanation, thanks. 

     

    Viorel, that is essentially what I ended up doing. Got it working last night, thanks.

    Wednesday, April 20, 2011 1:46 PM