What happens during compilation and execution of the program?

#include <iostream>
using namespace std;

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

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

int main() {
    B b;
    return 0;
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
Обратная Связь
Зарегистрируйся сейчас
или Подпишись на будущие тесты