Let's implement a program that knows the types, cat and dog, and that stores a mixed list of cats and dogs without using any runtime polymorphy:
- First, we include all the needed headers and define that we use the std namespace:
#include <iostream> #include <variant> #include <list> #include <string> #include <algorithm> using namespace std;
- Next, we implement two classes that have similar functionality but are not related to each other in any other way, in contrast to classes that, for example, inherit from the same interface or a similar interface. The first class is cat. A cat object has a name and can say meow:
class cat { string name; public: cat(string n) : name{n} {}
void meow() const { cout << name << " ...