C++ Constructor overloading

Description

C++ Constructor overloading

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>

using namespace std;
class Employee// w w w.  j a va 2 s. com
{
  public:
    Employee()
    {
        cout << "constructing employee No Name" << endl;
        name = "No Name";
        workHour = 0;
        salary = 0.0;
    }
    Employee(const char *pName)
    {
        cout << "constructing employee " << pName << endl;
        name = pName;
        workHour = 0;
        salary = 0;
    }
    Employee(const char *pName, int xfrHours,double xSalary)
    {
        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("abc");
    Employee s1("def", 80, 2.5);

    return 0;
}



PreviousNext

Related