#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();
}
通过公共函数为私有成员赋值
最新推荐文章于 2022-04-13 18:45:53 发布