dear all,

when I try and compile the following code I am recieved a linker error. Can some one steer me in the right direction. Also are my use of the virtual statments correct? many thanks tim

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;



class doctor{

    protected:
    string newname;
    string address; 
    int payrate; 
    int hours;
    int age;   

    public:

    doctor();   //constructor
    virtual ~doctor();
    virtual void set_Name(string itsname);  
    virtual string get_Name();  

    virtual void set_Address(string itsaddress);
    virtual string get_Address();    

    virtual void set_Age(int itsage);  
    virtual int get_Age();   

    virtual void set_Hours(int itshours);  
    virtual int get_Hours();  

    virtual void set_Payrate(int itspay);
    virtual int get_Payrate();  

    void get_holidaypay();
    virtual int calculate_pay();

    };          //end of class declaration

    doctor::doctor()
    {    
    } 

    doctor::~doctor()
    {
    cout<<"Doctor Destructer called"<<endl;
    }                                         

    void doctor::set_Name(string itsname){
    newname=itsname;
     }
    string doctor::get_Name(){
    return newname;
    }

    void doctor::set_Address(string itsaddress){
    address=itsaddress;
    }

    string doctor::get_Address(){
    return address;
    }

    void doctor::set_Age(int itsage){
    age=itsage;
    }

    int doctor::get_Age(){
    return age; 
    }

    void doctor::set_Hours(int itshours){
    hours=itshours;
    }

    int doctor::get_Hours(){
    return hours;
    }

    void doctor::set_Payrate(int itspay){
    payrate=itspay;
    }

    int doctor::get_Payrate(){
    return payrate;
    }

    void doctor::get_holidaypay(){
    cout<<"You Have 2 months off "<<endl;
    }

    int doctor::calculate_pay()
    {
    return payrate*hours;
    }


    //Junior Doctor Class 

    class junior:virtual public doctor
    {
    public:
    junior();
    virtual ~junior();
    virtual void getholidaypay();
    }; 

    void junior::getholidaypay()
    {
    cout<<"You Have weekend off "<<endl;
    }

    junior::~junior()
    {
    cout<<"junior destroctor called"<<endl;
    }


    //Consultant Class
    class consultant:virtual public doctor
    {
    public:
    virtual void getholidaypay();
    consultant();  
    virtual ~consultant();

    };                   

   consultant::~consultant()
   {
   cout<<"Consultant Destructor"<<endl;
   }

   void consultant::getholidaypay()
   {
   cout<<"You Have 6 months off "<<endl;
   }


int main(int argc, char *argv[])
{
  doctor* Array[5];
  doctor* newdoctor;
  int choice;
  int i;

  for(int i=0;i<5;i++)
  {
  cout<<"1.doctor, 2.Junior, 3.Consultant"<<endl;
  cin>>choice;

  if (choice==2)
      newdoctor = new junior;
  else if (choice==3)
      newdoctor = new consultant;
  else
      newdoctor = new doctor;

  Array[i]=new doctor;

  }

  cout<<"\n";

  for(i=0;i<5;i++)
  {
  Array[i]->get_holidaypay();
  delete Array[i];
  }


  system("PAUSE");  
  return 0;
}

Define the Constructors for junior and consultant.

junior::junior()

and

consulant::consultant()

, or remove the

junior();

and

consultant();

lines in the class declarations.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.