https://www.cnblogs.com/Bear-Study-Hard/archive/2006/01/09/313551.html 看了上面这篇文章有感,特做了个小样板,以加深对于this在派生类中的理解 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace Co…
using System; namespace ConsoleApp1 { class Program{ static void Main(string[] args){ B b = new B(); } } class A{ public A(){ Console.WriteLine("基类的构造函数初始化!"); } } class B:A{ public B(){ Console.WriteLine("派生类构造函数初始化!"); } } } 输出: 分析:…
三.多层继承的派生类 1.多层继承的派生类只需在构造函数的初始化列表中写出直接基类的构造函数即可 class student { public: student(int n, string nam) { num = n; name = nam; } }; class student1 : public student { public: student1(int n, string nam, int a) :student(n, nam) {age = a;} }; class student2…
二.有内嵌对象的派生类 1.一般来说,我们会这样定义构造函数 student( int i, string nam, int pid, string pnam, int sid) : person( i, nam),parent(pid,pnam){ stuid = sid; } person是基类的构造函数,parent是该派生类内嵌的person子对象 2.具体例子 #include <iostream> using namespace std; class A { int dataA…