C++ Constructor invoke another constructor from the same class
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class Employee{// www. j a va 2 s . c om public: Employee(const char *pName,int xfrHours,double xSalary){ cout << "constructing employee " << pName << endl; name = pName; workHour = xfrHours; salary = xSalary; } Employee() : Employee("No Name", 0, 0.0) {} Employee(const char *pName): Employee(pName, 0, 0.0){} protected: string name; int workHour; double salary; }; int main(int argcs, char* pArgs[]){ Employee noName; Employee s2("abc"); Employee s1("def", 80, 2.5); return 0; }