c++ - No matching function for call to classname::constructor -
this question has answer here:
class transport{ private: int weight; // member variable (private) int capacity; // member variable (private) int speed; // member variable (private) public: transport(int aweight, int acapacity, int aspeed) { // default constructor if(aweight > 0) { // perform validation @ time of creating object weight = aweight; } else { weight = 0; } if(acapacity > 0) { // perform validation @ time of creating object capacity = acapacity; } else { capacity = 0; } if(aspeed > 0) { // perform validation @ time of creating object speed = aspeed; } else { speed = 0; } } void carrygoods(); // member function (public) -> each transport has carrying goods functionality. }; class landtransport : public transport{ // inherit transport class private: char * transportationmode; // member variable (private) char * vehicletype; // member variable (private) public: landtransport(char * atransporationmode, char * avehicletype) { transportationmode = new char[strlen(atransporationmode)+1]; strcpy(transportationmode, atransporationmode); vehicletype = new char[strlen(avehicletype)+1]; strcpy(vehicletype, avehicletype); } };
can please describe, wrong here , best practice?
your derived class has constructor doesn't provide parameters of parent's constructor.
landtransport(char * atransporationmode, char * avehicletype)
should below (for example):
landtransport(char * atransporationmode, char * avehicletype) : transport(0,0,0) ^^^^^^^^^^^^^^^^^^
Comments
Post a Comment