Code:
class Employee//Class called employee
{
public:
// constructor
// WRONG: Employee(): Age(18) ,YearsOfService(1) ,Salary(10000){} - INSTEAD:
Employee(int initialAge = 18, int initialYearsOfService = 1, int initialSalary = 10000);
...
};
Employee::Employee(int initialAge,int initialYearsOfService,int initialSalary)
: ItsAge(initialAge), ItsYearsOfService(initialYearsOfService), ItsSalary(initialSalary)
{ }
I think that is what you want - an initialization list to initialize your values, and default values for when they are not specified. If you wanted two separate constructors you could also use this -- notice the use of the actual member variables (i.e. ItsAge instead of Age) in the initialization list:
Code:
Employee::Employee() : ItsAge(18), ItsYearsOfService(1), ItsSalary(10000)
{ }