Skip to main content

Practice · 2 of 3

explicit shuts the trap

CHALLENGE
Difficulty: intermediate+25 XP

Implement class Meters with explicit Meters(double v) storing v privately and double value() const. The test proves Meters m = 3.0; must NOT compile while Meters m{3.0}; must — your class needs exactly one explicit one-argument constructor.

Back to lesson: Practice: Classes, constructors, invariants