C
Christian Christmann
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;
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:
perator=( const CLASS_A &dst )
{
a = dst.a;
}
However, this doesn't work since the operator is never invoked.
What did I wrong?
Thank you
Chris
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;
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:
{
a = dst.a;
}
However, this doesn't work since the operator is never invoked.
What did I wrong?
Thank you
Chris