Christian Christmann <[EMAIL PROTECTED]> wrote:

Hi,

how do I define an assignment operator which is supposed to copy
all member attributes of one object to another where both objects are
given as pointers?

Example:

        CLASS_A *source = new CLASS_A;
        ....
        CLASS_A *dst = new CLASS_A;
        dst = source;

This assigns the *pointers*. What you want is to copy the objects the pointers 
point to.
You must dereference the pointers.

I want that all attributes of object "source" are also assigned to object
"dst".

My idea was to define the operator in the header file of class CLASS_A:

        class CLASS_A
        {
                public:
                        void operator=( const CLASS_A & );
                ...
                private:
                        int a;
                ...
        }

And in the source code:

        void CLASS_A::operator=( const CLASS_A &dst )
        {
                a = dst.a;
        }

However, this doesn't work since the operator is never invoked.

What did I wrong?


Write
        *dst = *source;
Now your operator= should be invoked.

Thank you


Chris




Cheers
Maett
_______________________________________________
Help-gplusplus mailing list
Help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to