标签:之间 ring eth 面向 mes 描述 意义 man 文件包含
1 class Parent 2 { 3 int mv; 4 public: 5 void method(); 6 }; 7 8 class Child : public Parent//描述继承关系 9 { 10 11 };
1 // 继承.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 // 3 #include <iostream> 4 #include <string> 5 using namespace std; 6 class Parent 7 { 8 string age; 9 string name; 10 string height; 11 string sex; 12 public: 13 Parent() 14 { 15 cout << "we are parent!!" << endl; 16 } 17 Parent(string _age,string _name,string _height,string _sex) 18 { 19 age = _age; 20 name = _name; 21 height = _height; 22 sex = _sex; 23 } 24 void HELLO() 25 { 26 cout << "hello world" << endl; 27 cout << "my name is " << name << endl; 28 cout << "my age is " << age << endl; 29 cout << "my height is " << height << endl; 30 cout << "my sex is " << sex << endl; 31 } 32 }; 33 class Child : public Parent 34 { 35 public: 36 Child() 37 { 38 cout << "we are child" << endl; 39 } 40 }; 41 int main() 42 { 43 44 Parent Father("48","mingxing","180cm","man"); 45 Father.HELLO(); 46 Child CHENGE; 47 //子类可以初始化父类 48 Parent Mother = CHENGE; 49 }
标签:之间 ring eth 面向 mes 描述 意义 man 文件包含
原文地址:https://www.cnblogs.com/chengeputongren/p/12240682.html