Quiz · Classes and OOP · lesson 11 of 15
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); }Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.