You can use a dynamic_cast to test whether a base class pointer actually points to a specific derived class object (or one of its derived classes).
Code:
bool Derived::TestPointer(Base* ptr)
{
return dynamic_cast<Derived*>(ptr) != 0;
}
You would have to add just this one virtual function to all derived classes, but it would only be the one function, not separate functions with different names for each derived class type. Also note that this will return true if the pointer points to a class derived from Derived or its children.
For question 2, if you have already checked that the pointer refers to the correct derived class, then a cast is the best way. I prefer a static_cast for this situation:
Code:
static_cast<bob*>(pointer)->function();
Note that both of these situations are often (but not always) a signal that your design could be improved. You don't usually want to know what the base class pointer pointer points to, you just want to use its interface and let the derived classes implement the interface appropriately. You might want to consider rethinking whether the derived classes really model an is-a relationship.