I am getting this error in the second constructor for Class MailCarrier.
mailcarrier.cpp(11) : error C2512: 'Employee' : no appropriate default constructor available
I'm trying to incorporate composition and inheritance into my program.
:idea:Any help would be appreciated:idea:
//MailCarrier.h
#ifndef MAILCARRIER_H
#define MAILCARRIER_H
#include "Employee.h"
#include <iostream>
using std::cout;
using std::endl;
class MailCarrier : public Employee
{
public:
MailCarrier();
MailCarrier( const string &, const string &, const string &, const HireDate &, double );
void setPayRate( double );
double getPayRate() const;
void getHoursFromUser();
double biWeeklySalary( double );
private:
double payRate;
double hours[12];
double totalPay;
};
#endif
//MailCarrier.cpp
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "MailCarrier.h"
//Constructor
MailCarrier::MailCarrier()
{
for (int i = 0; i <= 12; i++)
hours[i] = 0;
}
//Constructor
MailCarrier::MailCarrier( const string &first, const string &last, const string &ssn,
const HireDate &, double pay )
//explicitly call base-class constructor
: Employee( first, last, ssn, HireDate )
{
setPayRate( pay ); // validate and store payRate
}
// function to set payRate
void MailCarrier::setPayRate( double pay )
{
payRate = ( pay > 0.0 && pay < 35.0 ) ? pay : 17.17;
}
double MailCarrier::getPayRate() const
{
return payRate;
}
//Function to get hours from user
void MailCarrier::getHoursFromUser()
{
double dailyHours;
for (int j = 0; j <= 11; j++)
{
cout << "Enter hours for day " << j+1 << ": ";
cin >> hours[ j ];
}
}//End function
//Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "HireDate.h"
#include <string>
using std::string;
class Employee
{
public:
Employee( const string &, const string &, const string &, const HireDate & );
~Employee();
void setFirstName( const string & );
string getFirstName() const;
void setLastName( const string & );
string getLastName() const;
void setSocialSecurityNumber( const string & );
string getSocialSecurityNumber() const;
void print() const;
private:
string firstName;
string lastName;
string socialSecurityNumber;
const HireDate hireDate;
};
#endif
//Employee.cpp
#include <iostream>
using std::cout;
using std::endl;
#include "Employee.h"
#include "HireDate.h"
//constructor
Employee::Employee(const string &first, const string &last, const string &ssn, const HireDate &dateOfHire )
: firstName( first ), lastName( last ), socialSecurityNumber( ssn ), hireDate( dateOfHire )
{
}
Employee::~Employee() //destructor
{
}
//function to set Employee's first name
void Employee::setFirstName( const string &first )
{
firstName = first;
}
//function to get Employee's first name
string Employee::getFirstName() const
{
return firstName;
}
//function to set Employee's last name
void Employee::setLastName( const string &last )
{
lastName = last;
}
//function to get Employee's last name
string Employee::getLastName() const
{
return lastName;
}
// function to set Employee's Social Security Number
void Employee::setSocialSecurityNumber( const string &ssn )
{
socialSecurityNumber = ssn;
}
//function to get Employee's Social Security Number
string Employee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
}
//function to print Employee object
void Employee::print() const
{
cout << "Employee: " << getFirstName() << ' ' << getLastName()
<< "\nSocial Security Number: " << getSocialSecurityNumber()
<< "\nDate Hired: " << &hireDate << endl;
}