I'm self studying from the book, C++ Primer Plus Fifth Edition, by Stephen Prata. The following relates to Chapter 13, Page 699, Programming Exercise #4. One task is to write the derived class method definitions based upon the given prototypes. The following are the said prototypes.
class Port
{
private:
char *brand;
char style[20]; // i.e. tawny, ruby, vintage
int bottles;
public:
Port(const char *br = "none", const char *st = "none", int b = 0);
Port(const Port &p); // copy constructor
virtual ~Port() { delete [] brand;}
Port & operator=(const Port &p);
Port & operator+=(int b);
Port & operator-=(int b);
int BottleCount() const {return bottles;}
virtual void Show() const;
friend ostream &operator<<(ostream &os, const Port &p);
};
class VintagePort : public Port
{
private:
char * nickname; // i.e. The Noble, or Old Velvet, etc.
int year; // vintage year
public:
VintagePort();
VintagePort(const char *br, int b, const char *nn, int y);
VintagePort(const VintagePort &vp);
~VintagePort() {delete [] nickname;}
void Show() const;
friend ostream & operator<<(ostream &os, const VintagePort & vp);
};
You will note that the base class destructor is virtual. That the derived class destructor is implemented inline.
I was creating the derived class method definitions in a cpp file and couldn't get the project to progressively compile correctly. At my first method definition, a default constructor, the compiler kept spitting out this error message:
Chapter-13\pe-13-04\port.cpp|74|undefined reference to `vtable for VintagePort'
The line number was pointing to my derived class constructor definition. I did some googling around and came across this workaround. I removed the inline effect of the derived class destructor, made that into a method definition in the cpp file and presto, compilation succeeded.
Am I to assume that the example in the book, as regards the inline feature of a derived class destructor, is in error. Are there any other explanations.