Sunday, 10 April 2016

c++ - Undefined reference to vtable in final class constructor and destructor

Hello I am trying to learn c++ from a book "C++ an introduction to programming by Jesse Liberty and Jim Keogh" I am doing the questions for chapter 12 multiple inheritance. Q4 asks me to derive car and bus from vehicle with car as an adt and then derive sportscar, wagon and coupe from car and implement a non pure virtual function from vehicle in car. It is compiling on codelite but at build time it gives the error





undefined reference to 'vtable for Coupe' on the constructor and destructor for Coupe




Please can anyone tell me what I am doing wrong so I can learn more about how to handle virtual function definitions correctly with vtables.



#include 

using namespace std;


class Vehicle
{
public:
Vehicle(){};
virtual ~Vehicle(){};
virtual int GetItsSpeed() = 0;
int GetItsTyreSize();
virtual int GetItsRegistration() { return ItsRegistration; }
protected:
int ItsSpeed;

int ItsRegistration;
};

class Car : public Vehicle
{
public:
Car(){};
virtual ~Car(){};
virtual int GetItsSpeed() = 0;
int GetItsBootSize() { return ItsBootSize; }

int GetItsRegistration() { return ItsRegistration; }
virtual int GetItsRadioVolume() = 0;
int GetItsTyreSize() { return ItsTyreSize; }
protected:
int ItsBootSize;
int ItsRadioVolume;
int ItsTyreSize;
};

class Bus : public Vehicle

{
Bus(){};
~Bus(){};
public:
int GetItsSpeed() { return ItsSpeed; }
int GetItsPassengerSize() { return ItsPassengerSize; }
private:
int ItsPassengerSize;
};


class SportsCar : public Car
{
public:
SportsCar(){};
~SportsCar(){};
int GetItsSpeed() { return ItsSpeed; }
int GetItsPowerSteeringAccuracy() { return ItsPowerSteeringAccuracy; }
private:
int ItsPowerSteeringAccuracy;
};


class Wagon : public Car
{
public:
Wagon(){};
~Wagon(){};
int GetItsSpeed() { return ItsSpeed; }
int GetItsTrailerSize() { return ItsTrailerSize; }
private:
int ItsTrailerSize;

};

class Coupe : public Car
{
public:
Coupe(){ ItsTyreSize = 10; }
~Coupe(){};
int GetItsSpeed();
int GetItsInteriorStyle() { return ItsInteriorStyle; }
int GetItsRadioVolume() { return ItsRadioVolume; }

private:
int ItsInteriorStyle;
};

void startof()
{
Coupe MariesCoupe;
cout << "Maries Coupe has a tyre size of "
<< MariesCoupe.GetItsTyreSize() << " .\n\n";


}

int main()
{
startof();
return 0;
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...