So I am trying to compile this simple code:
// In Test.h
#include <iostream>
using namespace std;
class A{
public:
virtual string f (string&);
};
class B : public A{
public:
B (string);
string f (string&);
};
// In Test.cpp
#include <iostream>
#include "Test.h"
using namespace std;
B :: B (string row){
cout << "HERE";
}
string B :: f (string& x){
cout << "Test";
}
It seems simple enough but I keep getting a Undefined reference to 'vtable for A' error (compiler is MINGW with Eclipse IDE). When I take out the constructor implementation for B, the code compiles fine. What am I missing or is this a linker error?
I think you either have to make
A::f(string&)abstract by writing= 0at the end of the declaration, or actually provide an implementation ofA::fSince currently the virtual function
A::fdoes not exist, the compiler cannot create a vtable for it (the virtual function table).