I have an employee class that stores various details about, and one of those details involves another class clled date. I want to initialise this class in employye constructor with a birthdate. Problem is it doesn't work!! Its kinda hard to explain...
my emplyee class where you can see const Date &dob is myiniialiser
i have a private Date dateOfBirth data member in class employee
Can anyone help please
// Fig. 13.10: Employee.cpp
// Abstract-base-class Employee member-function definitions.
// Note: No definitions are given for pure virtual functions.
#include <iostream>
#include "Employee.hpp" // Employee class definition
#include "Date.hpp"
using std::string;
// constructor
Employee::Employee( const string &first, const string &last, const string &ssn, const Date &dob )
: firstName( first ), lastName( last ), socialSecurityNumber( ssn ), dateOfBirth(dob) {
// empty body
} // end Employee constructor
//Virtual destructor
Employee::~Employee(){std::cout << "Destroying Base" << std::endl;};
// set first name
void Employee::setFirstName( const string &first ) {
firstName = first;
} // end function setFirstName
// return first name
string Employee::getFirstName() const {
return firstName;
} // end function getFirstName
// set last name
void Employee::setLastName( const string &last ) {
lastName = last;
} // end function setLastName
// return last name
string Employee::getLastName() const {
return lastName;
} // end function getLastName
// set social security number
void Employee::setSocialSecurityNumber( const string &ssn ) {
socialSecurityNumber = ssn; // should validate
} // end function setSocialSecurityNumber
// return social security number
string Employee::getSocialSecurityNumber() const {
return socialSecurityNumber;
} // end function getSocialSecurityNumber
//set date of birth
void Employee::setDateOfBirth(const Date &dob) {
dateOfBirth = dob;
}
//return date of birth
Date Employee::getDateOfBirth() const {
return dateOfBirth;
}
// print Employee's information (virtual, but not pure virtual)
void Employee::print() const {
std::cout << getFirstName() << ' ' << getLastName()
<< "\nsocial security number: " << getSocialSecurityNumber()
<< "\nDate of Birth: " << this->dateOfBirth;
} // end function print
Did you compile the code? If there is a problem the compiler will probably give you better information. For example it may tell you "what" expression result is unused.