質問

次のような操作を行うと、

class Obj
{
public:
    int* nine;
};

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

then Obj1 Obj2 nine は同じ 8 を指しますが、彼らは同じポインタを共有していますか?つまり:

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

Obj2 nine Necronine を指しますか、それとも 8 を指し続けますか?

役に立ちましたか?

解決

  

Obj2のネクロニンに対する9つのポイントは、   または、8を指したままになりますか?

8を指したままになります。この行が実行されると: Obj Obj2 = Obj1; //すべてのオブジェクトには独自のポインターがあります obj1.nine value(copy) obj2.nine にコピーされ、それがそれです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top