posts - 1,  comments - 0,  trackbacks - 0

#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 on 2007-02-14 18:01 风风 阅读(102) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2007年2月>
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910

常用链接

留言簿(1)

随笔档案

链接

搜索

  •  

最新评论