I want to print variables of many types. I've made a class named IStringable, and some classes that derive from it. In my PrintVariable function I want to check whether the parameter derives from IStringable, and if it does then print it.
class IStringable {
public:
virtual ~IStringable() { }
virtual std::string ToString() const = 0;
}
class Person : public IStringable {
public:
Person(const std::string name) : _name(name) { }
virtual std::string ToString() const { return _name; …Run Code Online (Sandbox Code Playgroud)