Creating a constructor

How would I create a default constructor here?
1
2
3
4
5
6
7
8
9
10
11
12
class Employee
{
private:
int idNum;
double hourlyRate;
public:
Employee();
void setIdnum(const int);
void setHourlyRate(const double);
int getIdNum();
double getHourlyRate();
}; 
closed account (SECMoG1T)
i see you got one, about defining it, it will depend with the values you want to assign to your class members for example

1
2
3
4
5
//case 1
Employee::Employee() :idNum(0),hourlyRate(0.0){}

//case 2
Employee::Employee(){}


are all good example
How you create a default constructor is like this:

Employee(){}; //Default Constructor

But if you aren't doing anything within the default constructor, then it is essentially pointless because there is already a default constructor and a default deconstructor that is instantiated regardless.

For example you could do:

Employee(){hourlyRate = 10.50}; //Constructor actually doing something
Last edited on
Thanks I thought that was what she wanted. The constructor to initialize the values. This Professor asks tricky questions sometimes.
Topic archived. No new replies allowed.