posts - 1,  comments - 0,  trackbacks - 0
  2007年2月14日

#include <iostream.h>
#include <windows.h>
/*
class Test {
public:
 int data;
 int flag;
};

int & getData(Test * test) //const
{
 return (int &)test->data;
}

int main()
{
 Test *test = new Test();
 test->data = 100;
 test->flag = 0;

 cout<<test->data<<"  "<<test->flag<<endl;
 getData(test) = 999;
 cout<<test->data<<"  "<<test->flag<<endl;
 Sleep(1000);
 return 0;
}
*/

class Test {
public:
 int data;
 int flag;
public:
 int & getData(Test * test) const;
};

int & Test::getData(Test * test) const
{
 return (int &)test->data;
}

int main()
{
 Test *test = new Test();
 test->data = 100;
 test->flag = 0;

 cout<<test->data<<"  "<<test->flag<<endl;
 test->getData(test) = 999;
 cout<<test->data<<"  "<<test->flag<<endl;
 Sleep(1000);
 return 0;
}

posted @ 2007-02-14 18:01 风风 阅读(102) | 评论 (0)编辑 收藏
仅列出标题  
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

链接

搜索

  •  

最新评论