Quiz · Classes and OOP · lesson 9 of 13
Quiz — a derived object by value
What does the program print?
#include <iostream>
struct Shape {
virtual int sides() const { return 0; }
};
struct Square : public Shape {
int sides() const override { return 4; }
};
int by_value(Shape s) { return s.sides(); }
int by_ref(const Shape& s) { return s.sides(); }
int main() { Square sq; std::cout << by_value(sq) << ' ' << by_ref(sq); }