June 2025
Intermediate to advanced
1093 pages
33h 24m
English
When using methods in class hierarchies, you need to be aware of a few things. Take a look at Listing 15.6: pay attention to which other methods print calls, and consider what you would expect. I have reduced the program to the essentials, which is why it looks somewhat theoretical.
// https://godbolt.org/z/YTK8PfcMc#include <iostream>struct Base { int eight_ = 8; int value() const { return eight_; } void print(std::ostream& os) const { os << value() << "\n"; }};struct Print : public Base { int nine_ = 9; void print(std::ostream& os) const { os << value() << "\n"; }};struct Value : public Base { int ten_ = 10; int value() const { return ten_; }};struct Both : public Base { int eleven_ = 11; int value() const { return ...
Read now
Unlock full access