1

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.

Rhathin
  • 1,176
  • 2
  • 14
  • 20
ShockCoding
  • 216
  • 2
  • 12
  • "Symbol could not be resolved" is not a compiler error. It is your IDE error. You need to set up your IDE properly. We have no idea what's wrong with your setup as we cannot see it. All we can see is your source code, which is [correct](https://ideone.com/f5kFSg) as far as the compiler is concerned (but [doesn't do](https://ideone.com/hI0rTa) what you want it to do). – n. m. could be an AI Nov 19 '18 at 11:36

0 Answers0