obj1 = new MyObject(); obj2 = new MyObject(); obj3 = new MyObject(); for(auto obj: std::vector<MyObject*>({obj1, obj2, obj3})) { obj->method(); }