您的位置:首页 > 其它

通过公共函数为私有成员赋值

2014-09-03 11:22 134 查看
#include <iostream>
using namespace std;
class Test
{
private:
int x;
int y;
public :
void setX(int a);
void setY(int b);
void display();
};
void Test::setX(int a)
{
x=a;
}
void Test::setY(int b)
{
y=b;
}
void Test::display()
{
cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
int main()
{
Test t1;
t1.setX(3);
t1.setY(4);
t1.display();
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: