Q:

Calling the correct overloaded function from a container class

This is something that's been bugging me for a while now.
So let's say you have your baseClass and derivedClass. You also have a container object of baseClass pointers that holds pointers to all the objects you're managing.
The problem comes when there's an overloaded function with arguments of the derived class.
Example:
function foo(baseClass, baseClass);
function foo(baseClass, derivedClass);
function foo(derivedClass, derivedClass);

vector<baseClass*> objectList;

objectList.push_back(new derivedClass());
objectList.push_back(new derivedClass());

foo(objectList[0], objectList[1]); // <-- Here's the problem.

Until now I've been doing something hackish, and that's static_cast-ing to the "correct" type based on a "getType()" enum member variable I've defined. It's really ugly and I'd like to know the correct way to pass these arguments as the derived class.
Or is this just bad design as a whole?
And no, the container class can't be of type derivedClass... baseClass is the base for several different classes. While it's in the vector, I don't care what object type it is. When I pass it into an argument, I'd like for the compiler to know what type it is.

A:

You're trying to do multiple dispatch.

