我似乎无法弄清楚为什么这个代码,
class test{ public: int number; test(int pass){ number = pass; } }; int main(){ test x(3); test y(2); test z[2]={x,y}; y.number = 1; cout << "z[0].number: " << z[0].number << endl; cout << "z[1].number: " << z[1].number << endl; cout << "x.number: " << x.number << endl; cout << "y.number: " << y.number << endl; return 0; }
得出这个输出,
z[0].number: 3 z[1].number: 2 x.number: 3 y.number: 1
而不是这个,
z[0].number: 3 z[1].number: 1 x.number: 3 y.number: 1