C++ Constructor with default arguments
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class Employee{//from w w w . ja v a 2 s.co m public: Employee(const char *pName = "No Name",int xfrHours = 0,double xSalary = 0.0){ cout << "constructing employee " << pName << endl; name = pName; workHour = xfrHours; salary = xSalary; } protected: string name; int workHour; double salary; }; int main(int argcs, char* pArgs[]) { Employee noName; Employee s2("Mary"); Employee s1("Tom", 80, 2.5); return 0; }