»
(07) C++14 Call Constructor in Constructor
(18) C++14 smart pointer and reference counter*
(19) C++14 pthread*
(20) C++14 synchronized locker--mutex*
(24) C++ time and sleep*
(25) C++ High Precision Computation*
(27) C++14 std::string*
(31) Advanced Level C++ Tech*
In Java, there is a function called this(a,b,c). It's used to construct a Object calling another constructor function with different parameters.
In C++, then, How to call other constructors in a constructor function?
Don't worry. Here we go.
C++ has the constructor function followed by colon, and has the class definition followed by colon too.
In C++, colon means 'extending from', means the constructor is extending from other constructor, means a class is extending from other class.
This is what I'm keeping using in my coding. This is what I know.
class Car:Vehical{
private:
int type;
std::string name;
public:
Car(std::string name):Car(name,1){
}
Car(std::string name,int type):Vehical(name,type){
this->name=name;
this->type=type;
}
}