12345678910111213141516171819202122
class A{ public: virtual void foo() = 0; }; class B : public A{ public: void foo(); }; class C : public A{ public: void foo(); }; //... std::vector<A *> v; v.push_back(new B); v.push_back(new C); for (auto o : v) o->foo();