#include <iostream>
#include <string>
using namespace std;
class test
{
private://私有成员类外不能够直接访问
int number;
public://共有成员类外能够直接访问
float socre;
public:
int rp()
{
return number;
}
void setnum(int a)
{
number=a;
}
};
void main()
{
test a;
//a.number=10;//错误的,私有成员不能外部访问
a.socre=99.9f;
cout<<a.socre<<endl;//公有成员可以外部访问
//a.setnum(100);//通过公有成员函数setnum()间接对私有成员number进行赋值操作
//cout<<a.rp();//间接返回私有成员number的值
cin.get();
system("pause");
}
私有成员函数_42-公有成员
最新推荐文章于 2021-05-09 11:43:27 发布