"error C2248: 'CObject::CObject' : cannot

2020-02-15 02:34发布

Possible Duplicate:
error using CArray

Duplicate : error using CArray


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 files\microsoft visual studio 9.0\vc\atlmfc\include\afxtempl.h"

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

HELP !

标签: c++ mfc
3条回答
smile是对你的礼貌
2楼-- · 2020-02-15 02:39

It means that your program is trying to construct an instance of CObject, which appears to be banned because CObject has a private constructor.

Maybe the CArray is trying to construct those instances? What does the rest of the program look like?

查看更多
神经病院院长
3楼-- · 2020-02-15 02:47

The problem is that you're constructing a CObject on the stack. Somewhere in your program you're attempting to pass a reference to a CArray object but you accidentally left out the "&" in the function prototype. For example:

void DoFoo(CArray cArr)
{
    // Do something to cArr...
}

^^^ The code above will cause the error you're having.

void DoFoo(CArray & cArr)
{
    // Do something to cArr...
}

^^^ The code above will not cause the problem.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-15 02:55

Write a constructor for your class (CPerson) and make it public. it should solve the problem.

查看更多
登录 后发表回答