小编Ena*_*mya的帖子

Memeber 变量作为 C++ 中的类变量是如何发生的?


我有个问题。我目前正在用 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)

c++ reference class class-variables member-variables

0
推荐指数
1
解决办法
33
查看次数