I want to call B::func2(int x, int y)
in A::func1(x)
, how to declare them?
class A {
public:
void func1(int x);
virtual void func2(int x, int y); // do not need implement in A
};
class B : public A {
public:
void func2(int x, int y) override; // override
};
void A::func1(int x) {
int y;
func2(x, y); // I want to use the version of A's subclass
}
int main()
{
B b;
b.func1(x); // call A::func1(x) first then call B::func2(x, y)
}
It won't compile, instead the following error message is shown
> clang++ test.cpp -std=c++11
Undefined symbols for architecture x86_64:
"typeinfo for A", referenced from:
typeinfo for B in test-bbac7f.o
"vtable for A", referenced from:
A::() in test-bbac7f.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
clang: error: linker command failed with exit code 1 (use -v to see invocation)