From: Ru on
Hi,
I am using VS2005. I have declared a simple global structure,
struct CDrawElement
{
bool m_bChildren;
CArray <int, int> ptArray;
};

I am getting these compllation errors,
1>d:\program files\microsoft visual studio 8\vc\atlmfc\include
\afxtempl.h(272) : error C2248: 'CObject::CObject' : cannot access
private member declared in class 'CObject'
1> d:\program files\microsoft visual studio 8\vc\atlmfc\include
\afx.h(558) : see declaration of 'CObject::CObject'
1> d:\program files\microsoft visual studio 8\vc\atlmfc\include
\afx.h(529) : see declaration of 'CObject'
1> This diagnostic occurred in the compiler generated function
'CArray<TYPE,ARG_TYPE>::CArray(const CArray<TYPE,ARG_TYPE> &)'
1> with
1> [
1> TYPE=int,
1> ARG_TYPE=int
1> ]

I saw this thread but couldnt understand.
http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/ae7fce491be19bbc

Any suggestions!!!!

Thanks!
From: Giovanni Dicanio on
"Ru" <ruspatil(a)gmail.com> ha scritto nel messaggio
news:d1aad9d7-1b85-4e1f-ae4d-ddc77b2e8c38(a)z10g2000prh.googlegroups.com...

> I am using VS2005. I have declared a simple global structure,
> struct CDrawElement
> {
> bool m_bChildren;
> CArray <int, int> ptArray;
> };
>
> I am getting these compllation errors,
> 1>d:\program files\microsoft visual studio 8\vc\atlmfc\include
> \afxtempl.h(272) : error C2248: 'CObject::CObject' : cannot access
> private member declared in class 'CObject'
> 1> d:\program files\microsoft visual studio 8\vc\atlmfc\include
> \afx.h(558) : see declaration of 'CObject::CObject'
> 1> d:\program files\microsoft visual studio 8\vc\atlmfc\include
> \afx.h(529) : see declaration of 'CObject'
> 1> This diagnostic occurred in the compiler generated function
> 'CArray<TYPE,ARG_TYPE>::CArray(const CArray<TYPE,ARG_TYPE> &)'
> 1> with
> 1> [
> 1> TYPE=int,
> 1> ARG_TYPE=int
> 1> ]

The problem here is that MFC's CArray container class is not copiable, i.e.
they defined *private* operator= and copy constructor for CArray to prevent
copies.

If you want a copiable array container you may want to use std::vector, e.g.

struct CDrawElement
{
bool m_bChildren;
std::vector<int> ptArray;
};

Giovanni



From: Giovanni Dicanio on
"Giovanni Dicanio" <giovanniDOTdicanio(a)REMOVEMEgmail.com> ha scritto nel
messaggio news:uU$FZMCcKHA.1652(a)TK2MSFTNGP05.phx.gbl...

> The problem here is that MFC's CArray container class is not copiable,
> i.e. they defined *private* operator= and copy constructor for CArray to
> prevent copies.

To be more precise, after reading CArray definition in <afxtempl.h>, it can
be found that CArray derives from CObject, and CObject has private copy
constructor and operator=; from CObject code in <afx.h>:

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


In addition to using std::vector, if a copiable array container template
class is required, CSimpleArray from ATL could be another option:

http://msdn.microsoft.com/en-us/library/50t8ya55%28VS.80%29.aspx

(The aforementioned class is part of ATL, but it can be used in MFC code as
well.)

Giovanni


From: Ru on
Thanks Giovanni.
Understood the reason. I will use std::vector instead.

Regards,
Ru
From: Goran on
On Nov 28, 1:49 pm, Ru <ruspa...(a)gmail.com> wrote:
> Thanks Giovanni.
> Understood the reason. I will use std::vector instead.
>
> Regards,
> Ru

You can also write your own assignment operator, e.g.

CDrawElement& CDrawElement::operator=(const CDrawElement& rhs)
{
if (this != &rhs)
{
ptArray.Copy(rhs.ptArray); // Copy is MFC container equivalent for
operator= ;-)
m_bChildren = rhs.m_Children;
}
return *this;
}

Goran.