operator= and CArray 
Author Message
 operator= and CArray

Can anyone just confirm what I'm thinking or point me in the right
direction?

I have three classes, say CDoc, CDisney & CMickey.

CDoc contains a CArray, which is composed of elements of CMickey.

CDisney is a user defined base class.

CMickey is derived from CDisney.

When I compile my program, I get errors like:
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(443) :
error C2582: 'CMickey' : 'operator =' function is unavailable
        c:\program files\microsoft visual studio\vc98\include\xlocale(467) :
while compiling class-template member function 'void __thiscall CArray<class
CMickey,class CMickey &>::SetAtGrow(int,class CMickey &)'
Generating Code...

The errors seem to indicate, (after some head scratching / rtfm'ing), that I
need to create an operator= function in my CMickey. This looks necessary
because the compiler is seeing, at some point in the CDoc code,
ArrayElementX = ArrayElementY, which is kinda saying CMickey Object =
CMickey Object.

The thing that's got me pondering about creating my operator= function is
that the CMickey class, being derived from CDisney, can't copy some of the
relevant CDisney stuff because it doesn't know about it/it's private. Is the
appropriate way to get round this to create an operator= function is the
base classs CDisney as well, then call it from the operator= in the derived
class CMickey. CMickey's operator= can copy the member variables that it can
see, CDisney's operator= can do the relevant ones for the base class....

I don't know how well I've explained it, but if anyone can follow what I'm
getting at, I'd appreciate any comments -

Many thanks -

Tim.

--
---

I'm a newbie to VC++, so many thanks to anyone
kind enough to help me out with my questions,
even when some of'em may seem noddy. Cheers!



Mon, 25 Nov 2002 03:00:00 GMT  
 operator= and CArray
I think your headscratching must have been successfull. What you probably want
to do is (taken from the excellent book "C++ FAQs" by M.Cline):

Derived& Derived::operator= (const Dervied& d)
{
    Base::operator= (d);

    +++ copy the Derived parts+++

    return *this;

Quote:
}

with CMickey being Derived and CDisney being Base.

td

Quote:

> Can anyone just confirm what I'm thinking or point me in the right
> direction?

> I have three classes, say CDoc, CDisney & CMickey.

> CDoc contains a CArray, which is composed of elements of CMickey.

> CDisney is a user defined base class.

> CMickey is derived from CDisney.

> When I compile my program, I get errors like:
> c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(443) :
> error C2582: 'CMickey' : 'operator =' function is unavailable
>         c:\program files\microsoft visual studio\vc98\include\xlocale(467) :
> while compiling class-template member function 'void __thiscall CArray<class
> CMickey,class CMickey &>::SetAtGrow(int,class CMickey &)'
> Generating Code...

> The errors seem to indicate, (after some head scratching / rtfm'ing), that I
> need to create an operator= function in my CMickey. This looks necessary
> because the compiler is seeing, at some point in the CDoc code,
> ArrayElementX = ArrayElementY, which is kinda saying CMickey Object =
> CMickey Object.

> The thing that's got me pondering about creating my operator= function is
> that the CMickey class, being derived from CDisney, can't copy some of the
> relevant CDisney stuff because it doesn't know about it/it's private. Is the
> appropriate way to get round this to create an operator= function is the
> base classs CDisney as well, then call it from the operator= in the derived
> class CMickey. CMickey's operator= can copy the member variables that it can
> see, CDisney's operator= can do the relevant ones for the base class....

> I don't know how well I've explained it, but if anyone can follow what I'm
> getting at, I'd appreciate any comments -

> Many thanks -

> Tim.

> --
> ---

> I'm a newbie to VC++, so many thanks to anyone
> kind enough to help me out with my questions,
> even when some of'em may seem noddy. Cheers!



Mon, 25 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. 'operator =' for CArray derived class

2. CString/CArray and Overloaded = Operator

3. CArray::operator[] (int) const

4. CArray within CArray?

5. Sorting a CArray or another class that combines CMap and CArray functionality

6. MFC/C++ Guru needed: A CArray of CArrays

7. CArray of CArrays???

8. CArray of classes with an CArray inside problem

9. how to make CArray of CArray ?

10. A CArray of CArrays

11. CArray of CArray of CStrings...

 

 
Powered by phpBB® Forum Software