#include
class Base {
public:
Base(int v) : _value(v), _c('0') {}
Base(char c) : _value(0), _c(c) {}
int _value;
char _c;
};
class Derived : public Base {
public:
// 初始化基类需要透传参数至基类的各个构造函数,非常麻烦
//Derived(int v) :Base(v) {}
//Derived(char c) :Base(c) {}
//using Base::Base;
// 假设派生类只是添加了一个普通的函数
void display() {
std::cout <<"_c = "<< this->_c << std::endl;
std::cout << "_value = " << this->_value << std::endl;
std::cout << "b = "<_b << std::endl;
}
Derived(int b,int v):_b(b),Base(v){}
int _b;
};
int main() {
Derived d(4,5);
d.display();
}