constructore and initialisers

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 

// 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
Sorry I forgot to add xcode gives a "expression result unused" amber warning for employee constructor...
How is your class defined?

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.


Thanks everyone for your input! After reading and head scratching I have worked it out. Things seem to be working as expected now!

Thanks again!
Topic archived. No new replies allowed.