Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So, I am trying to use CArray like this :

 CArray<CPerson,CPerson&> allPersons;
   int i=0;
   for(int i=0;i<10;i++)
   {
      allPersons.SetAtGrow(i,CPerson(i));
      i++;
   }

But when compiling my program, I get this error :

"error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' c:program filesmicrosoft visual studio 9.0vcatlmfcincludeafxtempl.h"

I don't even understand where this is coming from.

HELP!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
132 views
Welcome To Ask or Share your Answers For Others

1 Answer

The error you are getting is because you are trying to use a CArray as a return value from what I can gather. If you change it from returning a CArray to taking a reference parameter instead, that will compile.

Try this:

class CPerson
{
public:
    CPerson();
    CPerson(int i);
    void operator=(const CPerson& p) {}
private:
    char* m_strName;
};

CPerson::CPerson()
{}

CPerson::CPerson(int i)
{
    sprintf(m_strName,"%d",i);
}

void aFunction(CArray<CPerson,CPerson&> &allPersons)
{
    for(int i=0;i<10;i++)
    {
        allPersons.SetAtGrow(i,CPerson(i));
        i++;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...