Can somebody help me figure out what I did wrong with my default constructor declaration
I'm getting an error message no appropriate constructor available
Thanks

TimeOff.h
class TimeOff
{
private:
	string name;
	int id;
	NumDays maxSickDays;
	NumDays sickTaken;
	NumDays maxVacation;
	NumDays vacTaken;
	NumDays maxUnpaid;
	NumDays unpaidTaken;
public:
        //default constructor
	TimeOff (string=" ", int=0, double=0, double=0, double=0, double=0,
		double=0, double=0);
	void setMaxSickDays(double);
        void setSickTaken(double);
	void setMaxVacation(double);
	void setVacTaken(double);
	void setMaxUnpaid(double);
	void setUnpaidTaken(double);
	double getMaxSickDays() const
	{return maxSickDays.getDays();}
	double getSickTaken() const
	{return sickTaken.getDays();}
	double getMaxVacation() const
	{return maxVacation.getDays();}
	double getVacTaken() const
	{return vacTaken.getDays();}
	double getMaxUnpaid() const
	{return maxUnpaid.getDays();}
	double getUnpaidTaken() const
	{return unpaidTaken.getDays();}
};

TimeOff.cpp

TimeOff::TimeOff(string n, int empid, double maxSick, double sTaken, double maxVac,
				 double vTaken, double maxUnpd, double uTaken)
{
	//check if string is empty
	if(!n.empty())
	//assign name
		name=n;
	//assign employee id
	empid=id;
	//initialize max sick days to default
	maxSickDays.setHours(maxSick);
        

}

Your .h file and .cpp file must match each other. You're implementing the constructor just about fine (in .cpp file) but are missing the declaration for that constructor.

Declare these ( in .h file)

TimeOff(); // this is the default constructor
TimeOff(string n, int empid, double maxSick, double sTaken, double maxVac,
				 double vTaken, double maxUnpd, double uTaken); // this is the constructor which takes parameters

And implement them like this ( using the constructor list )

TimeOff::TimeOff() : 
 name(""), id(0), maxSickdays(0), sickTaken(0), maxVacation(0), vacTaken(0), maxUnpaid(0), unpaidTaken(0) 
{}
// this is the implementation for the default constructor

TimeOff::TimeOff(string n, int empid, double maxSick, double sTaken, double maxVac,
				 double vTaken, double maxUnpd, double uTaken) :
name(n) , id(empid), maxSickdays(maxSick), sickTaken(sTaken), maxVacation(maxVac), vacTaken(vTaken), maxUnpaid(maxUnpd), unpaidTaken(uTaken)
{}
// this is the implementation for the constructor that takes parameters

Btw, if there is no default constructor available ( constructor with no parameters ), a compiler will generate one automatically.

Edited 4 Years Ago by Topi Ojala: n/a

This question has already been answered. Start a new discussion instead.