属性修改

include <iostream>

using namespace std;

//更改属性 形式 using 类1 :: 成员
//private protected 不能更改
class People;
class Student;

class People{
public:
void show();
protected:
char *m_name;
int m_age;

};

void People::show(){
cout<<m_name<<"的年龄是"<<m_age<<endl;
}

class Student :public People{
public:
void learn();
void ceshi(*pstu);
public:
using People ::m_name; // 将People 类两个成员protected改为 public
using People ::m_age;
float m_score;
private:
using People ::show; // 将People 类show成员改为private

};

void Student ::learn(){
cout<<m_name<<m_age<<m_score<<endl;
}

void main(){
class Student stu;
stu.m_name="mark";
stu.m_age=19;
stu.m_score=90;
stu.learn();
// Student.show(); 报错

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容