#include <iostream>
using namespace std;
#include <string>
class Person
{
public:
void setName(string name)
{
P_name = name;
}
string wName()
{
return P_name;
}
int w_Age()
{
P_age = 17;
return P_age;
}
void w_play(string girl)
{
P_playgirl = girl;
}
private:
string P_name;//可读,可写
int P_age;//只读
string P_playgirl;//只写
};
int main()
{
Person p1;
p1.setName("张三");
cout << p1.wName() << endl;
cout << p1.w_Age() << endl;
p1.w_play("小花");
system("pause");
return 0;
}
C++成员属性私有化
最新推荐文章于 2024-08-25 06:11:42 发布