What happens during compilation and execution of the program?

#include <iostream>
using namespace std;

class A {
public:
    A() { CoolVirt("A()"); }
    ~A() { CoolVirt("~A()"); }
protected:
    void CoolVirt(const char* str) { f(str); }
    virtual void f(const char* str) = 0;
};

class B: public A {
public:
    B() { CoolVirt("B()"); }
    ~B() { CoolVirt("~B()"); }
protected:
    void CoolVirt(const char* str) { f(str); }
    void f(const char* str) { cout << str << endl; }
};

int main() {
    B b;
    return 0;
}
Explanation
This error occurs when your application indirectly calls a pure virtual member function in a context where a call to the function is not valid. In most cases, the compiler detects this and reports the error when building the application. But depending on how your code is written, sometimes the problem is detected only at run-time.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести