#include <stdio.h>
class A {
public:
virtual void print();
A();
};
class B :public A {
public:
void print();
B();
};
class C :public B {
public:
void print();
C();
};
A::A(){
}
B::B(){
}
C::C(){
}
void B::print() {
printf("From B\n");
}
void C::print() {
printf("From C\n");
}
int main() {
B* object = new C;
object->print();
return 0;
}
When I try to compile this C++ file, I get the following error. Can't figure out the reason. I tried reading through similar undefined vtable questions on SO.
/tmp/ccpOkVJb.o: In function `A::A()':
test1.cpp:(.text+0xf): undefined reference to `vtable for A'
/tmp/ccpOkVJb.o:(.rodata._ZTI1B[_ZTI1B]+0x10): undefined reference to `typeinfo for A'
collect2: error: ld returned 1 exit status
If A::print() isn't meant to be implemented, declare it as pure:
class A {
public:
virtual void print() = 0;
A();
};
Otherwise, implement it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With