- From http://blog.csdn.net/hello_shadow/article/details/7007383
- #include <iostream>
- using namespace std;
- class Object
- {
- int &count;
- public:
- Object(int &cou):count(cou){};
-
- ~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;
- }
posted on
2013-10-23 17:22
码哥@杭州
阅读(
276)
评论()
编辑
收藏
举报