user3049522
user3049522

Reputation: 107

virtual function in c++ need an implemetation without implemetation its giving an error

#include <iostream>

using namespace std;

class A{
public:
  int a;
  virtual void fun();
};

int main(){A obj;}

getting error undefined reference to 'vtable for A'. I want to know why without implement virtual function giving this type of error.

Upvotes: 1

Views: 114

Answers (1)

Shivaraj Bhat
Shivaraj Bhat

Reputation: 847

That is because you are declaring the function (whether it would be normal member function or virtual function) but you are not defining it anywhere..!!

You can try this way, so that it would compile and run fine.!

class A{ public:int a; virtual void fun(){}; };

int main(){ A obj; }

Upvotes: 2

Related Questions