I have been thinking and searching this but I can't solve this question. I would like an object that when copied into another object, both objects share certain member variable. So, when I change the value of the member variable of object1, it's also changes the variable in object2. Example:
class ABC {
public:
int a = 5;
//...
}
int main() {
ABC object1;
ABC object2 = object1;
object2.a = 7; // now, object1.a is equal to 7
object1.a = 10; // now, object2.a is equal to 10
}
I know about copy constructors, but I am not sure if it applies here or there is a better method. I have been thinking about using pointers or references, but can't make the trick. Note that I don't want all the objects to share the same variable.