c*********n 发帖数: 128 | 1 Let's say I have a class name Coordinate and have its instances:
Coordinate a;
Then I have the following line:
Coordinate b = a;
In some cases, I wanna b to the same instance of a, i.e., &a and &b are the
same, how to make sure of that?
In other cases, I wanna b to only a copy of a, i.e, the fields within
instance b are all the same as that of a but &a and &b are different. How to
make sure of this?
Thanks. | H***a 发帖数: 735 | 2 If I understand ur questions correctly,the answer would be
(1) Coordinate& b=a;
(2) Coordinate b=a;
And you had better define the "=" yourself. | d*****a 发帖数: 110 | 3 Usually "=" needs to be explicitly defined if any deep-copy operations.
【在 H***a 的大作中提到】 : If I understand ur questions correctly,the answer would be : (1) Coordinate& b=a; : (2) Coordinate b=a; : And you had better define the "=" yourself.
|
|