To answer your question: you can use static_cast
if you know for certain that the instance is of the proper type, or dynamic_cast
otherwise. Something like this:
std::auto_ptr<baseclass> bar = classfactory::CreateBar();
if (derivedclass *der = dynamic_cast<derivedclass*>(bar.get())) {
der->foo(5);
}
However, code like this generally hints at bad design. You shouldn't need to access specifics of the derived class. Perhaps the base class interface is not as complete as it should be?