c++ - Constructor in inheritance -
c++ - Constructor in inheritance -
how declare constructor on class tanks, in order create new object, that:
tanks t34(durability, velocity, damage); here class:
#include <iostream> using namespace std; class vehicles{ private: double durability; double velocity; public: void drive() { cout << "drive\n"; } void info() { cout << durability << " " << velocity << "\n"; } vehicles(double d, double v) : durability(d), velocity(v) {} ~vehicles() {} }; class tanks:public vehicles{ private: double damage; public: using vehicles::vehicles; tanks(double dmg) : damage(dmg) {} void shot(); }; so re-create variable from:
vehicles(double d, double v) : durability(d), velocity(v) {} and add together class tanks.
just add together constructor in tanks:
tanks(double dmg, double v, double d):vechicles(d,v), dmanage(dmg) {} //^^call base of operations class constructor init base of operations part then should able create object of tanks follows:
tanks t34(durability, velocity, damage); c++ class inheritance constructor
Comments
Post a Comment