#include <iostream>
#include <vector>
#include <functional>
#include <utility>
// forward declarations of the base class and a helper function
class CAnimal;
void caller(CAnimal* a);
// base class with small extensions
struct CAnimal {
CAnimal() { mf = std::bind(caller, this); }
virtual void soundsLike() { std::cout<<"Base function\n"; }
// this will act as a virtual function
void makeNoice() { mf(this); }
std::function<void (CAnimal*)> mf;
};
// a helper function to call the real virtual function
void caller(CAnimal* a) {a->soundsLike();}
// the actual animals
struct CDog: public CAnimal {
virtual void soundsLike() { std::cout<<"Woof\n"; }
};
struct CCat: public CAnimal {
virtual void soundsLike() { std::cout<<"Miau\n"; }
};
int main()
{
// the animals
CDog dog;
CCat cat;
// the vector
std::vector<CAnimal> animalList;
animalList.push_back(dog);
animalList.push_back(cat);
// calling the fake virtual
animalList[0].makeNoice();
animalList[1].makeNoice();
}