Medium
Passing a Derived object where Base is expected
What does this program print?
main.cpp
#include <iostream>
struct Base {
virtual void speak() const { std::cout << "Base\n"; }
};
struct Derived : Base {
void speak() const override { std::cout << "Derived\n"; }
int extra = 42;
};
void print(Base b) {
b.speak();
}
int main() {
Derived d;
print(d);
}14 of 117 in C++