template <class A, class B> inline B* mycast( A* a)
{
return dynamic_cast<B>(a);
}
// try to specialize the mycast to handle when B==A, such as:
template <class A> inline A* mycast(A* a)
{
return a; // since type B is identical to A.
}
// OR what else I should do to implement this function??????
//....somewhere we try to use mycast()
test()
{
A* ap;
B* bp = mycast(ap); // I expect this will call the primary template function.
A* ap2 = mycast(ap); // I expect this will call the specialized tuned template function.
}
// unfortunately, above code is not run as I expected.
As a "derived question" from above, is the "dynamics_cast<A>(a)" EXACTLY(performance??) idential to "A(a)" when a is type of "A"???