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!
If
CPerson
is a complex object, maybe you should consider using pointersDon't forget to delete your array's content once it's not needed anymore
Are you using any of the Copy constructor or assignment operator of CObject ? ( CArray is derived from CObject)
For instance:
OR
Are you doing this?
EDIT: If you want to copy the elements in CArray, write a helper method CopyArray() and copy the elements manually.
I'm not totally sure of what your problem was, but take also a look at this: Microsoft CObject derived class specifications.
You might want to add this code:
Hope it helps for the future.
Is
CPerson
derived fromCObject
? Does it have aprivate
constructor? Your use ofSetAtGrow()
seems correct to me otherwise.If that doesn't work, you might try falling back to using the
Add()
function, as your loop doesn't seem to requireSetAtGrow()
.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 aCArray
to taking a reference parameter instead, that will compile.Try this:
Do you mean to say
CArray<CPerson> allPersons;
? I don't know how leaving out the contained type would lead to the reported error, but...