How to apply overloaded polymorphed function on elements of base class pointer vector
问题 I have a base class Object : struct Object{ }; and n (in this case 2) classes that inherit from this struct Integer : public Object{ int i_; Integer(int i) : i_{i}{} } struct Float : public Object{ float f_; Float(float f) : f_{f}{} } By (ab-)using polymorphism I can now store those two types in a vector: std::vector<Object*> object_list{new Integer(1), new Float(2.1), new Integer(3), new Float(4.2)}; But now I would like to add all those values together. I can think of... 1) ...defining