当前位置:首页 > Software > C++ > 正文内容

C++的继承和派生

chanra1n6年前 (2019-11-06)C++7330
#include <iostream>
using namespace std;
class fenshu
{
	public:
		int xuehao;
		int yuwen;
 }; 
 class wz_fenshu:public fenshu
 {
 	public:
 		int shuxue;
 }zhangsan;
 int main()
 {
 	zhangsan.xuehao=1;
 	zhangsan.yuwen=66;
 	zhangsan.shuxue=88;
 }

什么是继承,你是中国人,但是你也是人类,所以你既有中国人的属性,又有人类的属性。而中国人这个类是归属于人类这个类,故而可以说

class 人类 
{

 }; 
 class 中国人:public 人类
 {

 };

相信您早就发现了,public是什么意思呢?其实不只是有public,还有

image.png

他们代表着访问的控制,也就是说,不同的关键字,决定着您能否在别的类中使用属性。

扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://www.myfpga.cn/index.php/post/49.html

分享给朋友:

“C++的继承和派生” 的相关文章

c++类的构造函数

c++类的构造函数

 c++的目标之一是让使用类对象就像使用标准类型一样, 也就是说,常规的初始化语法不适用于类型Stock: int year=2001;  struct thing    {      char *pn;      int m;      };      thing amabob={"w...

数据类型及其占用空间

数据类型及其占用空间

#include<iostream> using namespace std; int main() { cout << "The size of int is&nb...

函数声明和使用

函数声明和使用

#include<iostream> using namespace std; int sum(int a,int b);//函数声明  int main() { cout <<&nb...

数据结构

数据结构

#include<iostream> using namespace std; struct books{ char name[10]; int num; float price; }book; int&nb...

C++ 数组的各类性质和用法

C++ 数组的各类性质和用法

#include<iostream>  using namespace std; void addarr(int *k,int len); //文中形如sizeof(x)/sizeof(x[0]) 是用数组占用空...