Sometimes a general category has no sensible default behavior. A generic fee rule cannot know its charge until a concrete rule supplies one. An abstract base class can state the required operation without providing an ordinary implementation for it.
#include <iostream>
class Rule {
public:
virtual int limit() const = 0;
virtual ~Rule() = default;
};
class SmallRule : public Rule {
public:
int limit() const override { return 3; }
};
int main() {
SmallRule rule;
const Rule& view = rule;
std::cout << view.limit() << '\n';
}
The = 0 after the virtual declaration marks a pure virtual function. It does not mean “return zero.” A class with an unimplemented pure virtual operation is abstract, so you cannot create a standalone object of that class. You can still use pointers and references to it. A concrete derived class supplies every required override before objects of that derived class can be created.
Unlike the previous lesson's base label, Rule::limit has no default answer here. A reporting function can still accept const Rule& and call limit: the concrete object must supply that operation. The caller need not choose between derived types itself.
In the task, both fee policies are already concrete: their overrides return safe placeholder numbers. You will give each policy its own calculation. Amounts are integer cents, avoiding decimal formatting concerns. The base destructor remains virtual, and the pure virtual declaration remains unchanged. Notice that the caller asks for a fee through the shared base interface while the derived class decides the amount.
Edit main.cpp; the supplied Console probes already call your code.
DailyFee::cents charge 25 cents per day for the supplied nonnegative day count. Expect Daily cents: 75.FreeLoan::cents return zero regardless of the day count. Expect Free cents: 0.Use Run to inspect the Console, then Submit to check your work.