#include <iostream>
using namespace std;
class Object
{
int &count;
public:
Object(int &cou):count(cou){};
//如果函数为Object(int cou)则count引用了形参。
~Object(){};
void SetValue(int cou)
{
count=cou;
}
void Display()
{
cout<<"the value of count in Object:"<<count<<endl;
cout<<"the address of count in main:"<<&count<<endl;
}
};
int main()
{
int count=10;;
Object obj(count);
obj.SetValue(9);
obj.Display();
cout<<"the value of count in main:"<<count<<endl;
cout<<"the address of count in main:"<<&count<<endl;
return 0;
}
类的引用类型成员
最新推荐文章于 2021-07-14 15:59:04 发布