views:

136

answers:

1

I know that if I do something like this:

class Obj
{
public:
    int* nine;
};

Obj Obj1; //Awesome name
int eight = 8;
Obj1.nine = &eight;
Obj Obj2 = Obj1; //Another Awesome name

then Obj1's and Obj2's nines will point to the same 8, but will they share the same pointer? I.e.:

int Necronine = 9;
Obj1.nine = &Necronine;
Obj2.nine == ???

will Obj2's nine point to Necronine, or will it remain pointing at 8?

+4  A: 

will Obj2's nine point to Necronine, or will it remain pointing at 8?

It will remain pointing at 8. When this line is executed: Obj Obj2 = Obj1; // every object has his own pointer the value(copy) of obj1.nine is copied into obj2.nine and thats it.

AraK
Thanx. The 8 was a typo, I'm fixing it now.
Keand64
Hah. I assumed assigning a value of 8 to the variable nine was deliberate and intentionally amusing. Certainly, it was more amusing than assigning 9 to nine, but perhaps less so than assigning 5 to twoPlusTwo would have been :)
csj