jeudi 2 février 2017

how to do shallow copy using assignment operator c++11

I am working on C++11 application. I am implementing assignment operator. I want that if I modify one value after the assignment both objects get modified.

Example:

Object o1, o2;
o1.setId("id1");
o2 = o1;
o2.setId("id2");
cout << o1.getId();  ------> this returns id2

How could I achieve that? any ideas

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire