#include <cstdlib>
#include <iostream>
struct A {
virtual ~A() {}
virtual void foo() const { std::cout << "A::foo()" << std::endl; }
virtual void bar() const { std::cout << "A::bar()" << std::endl; }
void baz() const { std::cout << "A::baz()" << std::endl; }
};
struct B : public A {
virtual void foo() const { std::cout << "B::foo()" << std::endl; }
void bar() const { std::cout << "B::bar()" << std::endl; }
void baz() const { std::cout << "B::baz()" << std::endl; }
};
int main() {
A * pA = new B; // 1
pA->foo();
pA->bar();
pA->baz();
delete pA;
return 0;
}
B::foo() B::bar() A::baz()
Программа скомпилируется, но не напечатает ничего.
B::foo() B::bar() B::baz()
Ошибка в строке 1