我有个问题。我目前正在用 C++ 编写一个小例子,无法弄清楚解释。这是我的问题:
#include <iostream>
using namespace std;
class X{
int& i ; /* int i; */
public :
X(int k=100):i(k){ }
X(`const` X& x):i(x.i){}
void setI(int k){i=k;}
int getI(){cout <<"adresse: "<< &i << " Contenue: "<<i<<endl ; return i;}
};
int main(){
int i =7;
X a(i);
a.getI();
a.setI(5);
a.getI();
cout << "the value of i is: " << i << endl;
X b(a);
b.getI();
cout << "the value of i is: " << i << endl;
X c; …Run Code Online (Sandbox Code Playgroud)