Hey guys, I am having a problem with a very simple inheritance program. I have made a base and derived class for a simple assignment. The strange thing is I cannot get the program to compile without including a cout which references one of the used functions in the application file into the base class' constructor. If i ommit this cout statement, the compiler returns the error:
Header file containing base class and derived class prototypes
Definition file:
I tried to rewrite a simple program with the same idea but could not replicate the error. The problem area is highlighted in the definition file below.test file.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const & __thiscall employee::getpaytype(void)const " (?getpaytype@employee@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
Header file containing base class and derived class prototypes
Rich (BB code):
#include <string>
#include <iostream>
using namespace std;
class employee
{
public:
employee(int eid, const char * name, float p,const char * ptype);
inline const string & getname() const;
inline float getpayrate() const;
inline const string & getpaytype() const;
float get_pay();
protected:
virtual void pay() =0;//pure virtual function ensures that employee is an Abstract base class
int employee_id;
string employee_name;
float payrate;
float tot_pay;
string paytype;
};
class manager : public employee
{
public:
manager(int Eid, const char *, float P, const char * P_type, int Supers);
inline int getsupervisors() const;
inline void set_supers(int);
virtual void pay();
private:
int supervisors;
};
Rich (BB code):
#include "headers.h"
employee::employee(int eid, const char* name, float p, const char * ptype)
{
employee_id = eid;
employee_name = name;
payrate = p;
paytype = ptype;
tot_pay = 0;
cout << "The value of name is " << name << " the value of ptype is " << ptype << "This is inside employee constructor.\n";
cout << "Using getname from withiin employee constructor: " << getname() << endl;
cout << "Using getpayrate() inside employee constructor: " << getpayrate() << endl;
//cout << "Using getpayrate() inside employee constructor: " << getpaytype() << endl;
//if the above line is not commented out, the program works
}
const string & employee::getname() const
{
return employee_name;
}
float employee::getpayrate() const
{
return payrate;
}
const string & employee::getpaytype() const
{
return paytype;
}
float employee::get_pay()
{
pay();
return tot_pay;
}
manager::manager(int Eid, const char * Name, float P, const char * P_type, int Supers)
:employee(Eid,Name,P,P_type),supervisors(Supers)
{
cout << "The value of name is: " << Name << " The value of P_type is " << P_type << endl;
}
void manager::pay()
{
tot_pay = payrate + payrate/100*5*getsupervisors();
}
int manager::getsupervisors() const
{
return supervisors;
}
void manager::set_supers(int supers)
{
supervisors = supers;
}