Assume I have a class:
class A {
public:
int key;
map<int,int> a;
};
Obj_A1 is an existing object of class A. Somewhere in my problem, I want to construct another object called Obj_A2 and update the members of Obj_A2 like this:
Obj_A2.key = Obj_A1.key + 1;
Obj_A2.a = Obj_A1.a; // When a is large, this copy operation will be really time consuming.
So I try to get around the real data transfer, considering that maybe I can assign the address of Obj_A2.a with the address of Obj_A1.a. In case, Obj_A2.a is just Obj_A1.a in the memory, and there is not data duplication at all.
So I did something silly (I am new to C++), which is, &Obj_A2.a = &Obj_A1.a
, and had some compiler error.
Does anyone know the right way to do this?
Thanks a lot.