"error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
Solution 1
Write a constructor for your class (CPerson) and make it public. it should solve the problem.
Solution 2
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.
Solution 3
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?
Attilah
Updated on July 02, 2020Comments
-
Attilah almost 4 years
Possible Duplicate:
error using CArrayDuplicate : 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 !
-
crashmstr about 15 yearsDuplicate from same author: stackoverflow.com/questions/864864/error-using-carray
-
-
Attilah about 15 yearsyes, i think it has to do with the fact that CArray is trying to construct an instance of CObject. but how do I circumvent the problem ?
-
Daniel Earwicker about 15 yearsLike I asked, what does the rest of the program look like? Post the shortest complete program that will demonstrate the problem, omitting the stuff generated by any wizards, etc.
-
Jeff D. about 11 yearsThis was exactly what I had done and chased the problem around until I searched here. Good call.
-
Eternal21 about 9 yearsIt doesn't even need to be a missing & in the function prototype. The problem in my code was missing & in variable declaration.
-
Ravi Maurya almost 6 yearsIt worked for me.Thanks.