A missing vtable usually means that the first non-built-in virtual member function has no definition

I am sure this question is repeated, but my code here is different, here is my code. It fails with the error "Undefined", not sure what is missing.

class Parent { public : virtual int func () = 0; virtual ~Parent(); }; class Child : public Parent { public : int data; Child (int k) { data = k; } int func() { // virtual function cout<<"Returning square of 10\n"; return 10*10; } void Display () { cout<<data<<"\n"; } ~ Child() { cout<<"Overridden Parents Destructor \n"; } }; int main() { Child a(10); a.Display(); } 

The following is O / P at compilation.

 Undefined symbols for architecture x86_64: "Parent::~Parent()", referenced from: Child::~Child() in inher-4b1311.o "typeinfo for Parent", referenced from: typeinfo for Child in inher-4b1311.o "vtable for Parent", referenced from: Parent::Parent() in inher-4b1311.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. 
+8
source share
2 answers

Parent::~Parent() is undefined.

You can put the definition directly in the class definition:

 class Parent { public : virtual int func () = 0; virtual ~Parent() {}; }; 

Or define it separately. Or, since C ++ 11, write virtual ~Parent() = default; .

In any case, the destructor needs to be defined.

+11
source

Well, I have the same problem and I can not find the answer to it

My code

 class Option { protected: double m_K; double m_rate; double m_T; double m_u; double m_d; double m_volatility; virtual double FSm(double S0, int m, int j) const = 0; public: Option(double strikePrice, double rate, double T, double u, double d, double volatility) : m_K(strikePrice) , m_rate(rate) , m_T(T) , m_u(u) , m_d(d) , m_volatility(volatility) {} ... virtual ~Option() = default; } class CallOption : public Option { protected: double FSm(double S0, int j, int m) const override; // This function is implemented in the .cpp file public: CallOption(double strikePrice, double rate, double T, double u, double d, double volatility) : Option(strikePrice, rate, T, u, d, volatility) {} ~CallOption() override = default; }; 

and I have a mistake

 Undefined symbols for architecture x86_64: "vtable for CallOption", referenced from: CallOption::CallOption(double, double, double, double, double, double) in CallOption.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 

Any idea?

Yours faithfully

0
source

All Articles