区分好继承类和封闭类,两者有很大的区别
一、继承类 在继承中,子类负责其直接基类的构造,至于如何构造需要看下面; 如何在子类中调用拷贝构造函数,看下面; #include <iostream> #include <bits/stdc++.h> using namespace std ; class Base { private : int _a; public : Base( int a= 0 ):_a(a){ cout << "Base = " <<_a<< " is created." <<endl;} Base( const Base& p):_a(p._a){ cout << "Base = " <<_a<< " is copied." <<endl;} ~Base(){ cout << "Base = " <<_a<< " is erased." <<endl;} }; class Derived: public Base { private : int _b; public : Derived( int a= 0 , int b= 0 ):Base(a),_b(b){ cout << "Derived = " <<_b<< " is created." <<endl;} Derived( const Derived& p):Base(p),_b(p._b){ cout << "Derived = " <<_b