Imagine the following scenario:
template<class T>
void myFunction(T *)
{
//do nothing
}
void myFunction(myBase * _base)
{
//do something with _base
}
int main( int argc, const char* argv[] )
{
myDerivedFromBase * ptr = new myDerivedFromBase;
myFunction(ptr); //calls the templated version
myFunction(static_cast<myBase*>(ptr)); //calls the correct version
delete ptr;
}
basically I want to achieve that the templated function gets called for pointers, that are not derived from my base. If a ptr is derived from myBase I want that the second version of myFunction gets called without the explicit cast. Is that possible?
Use type traits to prevent the template from binding:
If you can’t use C++0x, use Boost’s type traits library instead.