Im' having problem with pure virtual methods and forward class declaration. The following program compiles, but will not link.
class SubClass;
class SuperClass {
public:
virtual SubClass& GetSomething() = 0;
};
class SubClass: public SuperClass {
public:
SubClass& GetSomething();
};
SubClass& SubClass::GetSomething()
{
return *this;
}
int main()
{
SuperClass *obj = new SubClass();
SubClass result = obj->GetSomething();
return 0;
}
I'm getting the following error:
Undefined symbols for architecture x86_64:
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for SuperClass in classtest-56e822.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for SubClass in classtest-56e822.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator new(unsigned long)", referenced from:
_main in classtest-56e822.o
"___cxa_pure_virtual", referenced from:
vtable for SuperClass in classtest-56e822.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What am I doing wrong?