#include class Printer { public: virtual ~Printer() = default; virtual void print() const = 0; }; class Number_Printer : public Printer { public: Number_Printer(int value) : value { value } { } void print() const override { std::cout << value << std::endl; } private: int value; }; class Text_Printer : public Printer { public: Text_Printer(std::string const& value) : value { value } { } void print() const override { std::cout << '"' << value << '"' << std::endl; } private: std::string value; }; int main() { Number_Printer number { 5 }; Text_Printer text { "My text" }; number.print(); text.print(); }