[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Assignment operator
From: |
Christian Christmann |
Subject: |
Assignment operator |
Date: |
Fri, 25 Nov 2005 13:16:03 +0100 |
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::operator=( 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
- Assignment operator,
Christian Christmann <=