构造函数与基类的其他成员不同,不能被派生类继承,因此为了初始化基类中的成员变量,需要在派生类中调用基类的构造函数(即显式调用),如果派送类没有调用则默认调用基类的无参构造函数(即隐式调用).
显式调用的方式参考以下代码:
//基类 class animal{ protected: int height; public: animal(){ height=0; } animal(int height){ this->height=height; } }; //派生类 class fish:public animal{ public: fish(){ // } fish(int height):animal(height){ // } }; //fish m_fish(3); then animal->height = 3;
如对本文有疑问, 点击进行留言回复!!
FPGA/verilog 学习笔记(1)—— FPGA和HDL基础概念
2020年 浙江工业大学计算机科学与技术学硕 初试复试经验帖
网友评论