#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
/*
private:
类的私有成员
在类的内部能否访问(是)
在类的外部是否访问(否)
public:
类的公有成员
在类的内部能否访问(是)
在类的外部是否访问(是)
protected:
类的保护成员
在类的内部能否访问(是)
在类的外部是否访问(否)
*/
//定义一个基类(父类)
class Student
{
private://类的私有成员
int id;
public://类的公有成员
int ID;
Student()
{
cout<<"访问"<<endl;
}
void Student(int n)
{
cout<<""<<endl;
}
~Student()
{
}
int show();//类的内部进行方法声明
protected://类的保护成员
int t;
{
}
};
int Time::show()//类方法进行外部实现
{
cout<<"show11"<<endl;
return 0;
}
//定义一个派生类(子类)
/*
private:以私有的方式继承
基类的私有成员
在派生类内部能否访问(不能)
在派生类外部能否访问(不能)
基类的共有成员
在派生类内部能否访问(能)
在派生类外部能否访问(不能)
基类的保护成员
在派生类内部能否访问(能)
在派生类外部能否访问(不能)
public:以公有方式继承
protected:以保护方式继承
*/
class smallStudent: Student
{
public:
SmallStudent()
{
cout<<"派生类构造方法"<<endl;
//cout<<id<<endl;
cout<<ID<<endl;
cout<<t<<endl;
}
~SmallStudent()
{
cout<<"派生类析构方法"<<endl;
}
void subshow()
{
cout<<"subshow方法"<<endl;
}
};
int main()
{
//Student std;
SmallStudent sstu;
return 0;
}
类和派生类
最新推荐文章于 2023-06-08 23:07:20 发布