#include <unordered_set>
#include <iostream>
class Fooable
{
public:
Fooable() { registered.insert(this); }
~Fooable() { registered.erase(this); }
virtual void fooify() = 0;
static void fooify_all()
{
for(auto * f : registered)
f->fooify();
}
private:
static std::unordered_set<Fooable*> registered;
};
class Fruit : private Fooable
{
void fooify() override { std::cout << "Fruit::fooify" << std::endl; }
};
class Apple : public Fruit, private Fooable
{
void fooify() override { std::cout << "Apple::fooify" << std::endl; }
};
std::unordered_set<Fooable*> Fooable::registered;
int main()
{
Apple a;
Fooable::fooify_all();
return 0;
}