I'm trying to create an abstract class A
which is going to be inherited by class B
;
Class A
has one single pure virtual function, which is correctly defined by the B
class, however the code below doesn't compile, giving me a Symbol could not be resolved
error:
class A {
public:
A() {foo();}
virtual void foo() = 0;
};
class B : public A {
public:
B() : A() {}
void foo() override {}
};
int main() {
B b = B();
return 0;
}
Can someone explain me why? I thought the dynamic binding would allow me to call a pure virtual function in the base class constructor as long as it is defined by B
class (In the main I'm default-initializing a B
object, so foo()
is correctly defined);
What am I missing? Thanks.