We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Const Correctness and Class Design
C++Design class interfaces with const-qualified operations and deliberate constructors. Control implicit conversions and make allowed operations clear to callers.
This track uses C++. You can make it your practice mode to browse related content across the site.
3 exercises
Explore freely. Sign in to keep your progress.
Your learning sequence
- 1 Not solved yet. The accessor that will not let you look Practice · Easy
- 2 Not solved yet. Make temperature construction explicit Practice · Medium
- 3 Not solved yet. Keep ledger entries and their total consistent Practice · Medium
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
Why do these two calls print different names?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
#include <iostream>
struct Base {
virtual void who() const { std::cout << "Base" << std::endl; }
virtual ~Base() = default;
};
struct Derived : Base {
void who() const override { std::cout << "Derived" << std::endl; }
};
int main() {
Derived d;
Base sliced = d;
Base& ref = d;
sliced.who();
ref.who();
}