博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

学习c++:获得函数私有变量

Posted on 2008-07-29 16:30  浪端之渡鸟  阅读(320)  评论(0编辑  收藏  举报

#include "stdafx.h"
#include "iostream"
using  namespace std;
class C{

public:
 int  GetX(){return X;}
 void SetX(int X){this->X = X;}
private:
 int X;
};

void main(){
 C c;
 cout<<c.GetX()<<endl;
 cin.get();
 c.SetX(111);
 cout<<c.GetX()<<endl;
 cin.get();
 
}