Which lines need to be removed so that the code below compiles?
#include <iostream>

class A{
    public:
    virtual void foo() = 0;
};

void A::foo() { std::cout << "A foo"; }

class B : public A{};

class C : public A{
    public:
    void foo();
};

void C::foo() { std::cout << "C foo"; }

class D: public A{
    public:
    void foo();
};

void D::foo() { A::foo(); }

class E: public A{
    public:
    //using A::foo;
    void foo(int) { std::cout << "E foo"; }
};

int main(){
    (new A)->foo();  // 1
    (new B)->foo();  // 2
    (new C)->foo();  // 3
    (new D)->foo();  // 4
    (new E)->foo(2); // 5
}
Explanation
Classes A, B, and E contain a pure virtual method and are therefore abstract classes. Objects of abstract classes cannot be created.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты