I read a few posts on the usage of static and dynamic casts specifically from http://stackoverflow.com/questions/332030/when-should-staticcast-dynamiccast-and-reinterpretcast-be-used
I have a doubt regarding the usage of cast in the following manner. Can someone verify the below mentioned code:-
This is upward casting in inheritance hierarchy
template<class Base, class Derived>
inline Handle<Base> STATIC_CAST(Handle<Derived> hd) {
Handle<Base> hb;
Derived* dp = hd.get(); // Assume this gives pointer of derived class object
Base* bp = static_cast<Base*> (dp);
if(bp) {
hb = Ptr2Handle(bp); // Assume this give reference to Handle
}
return hb;
}
*Derived is actually the derived class from class Base.
What about downward casting in the following code?
template<class Base, class Derived>
inline Handle<Derived> DYNAMIC_CAST(Handle<Base> hb) {
Handle<Derived> hd;
Base* bp = hb.get();
Derived* dp = dynamic_cast<Derived*> (bp);
if(dp) {
hd = Ptr2Handle(dp);
}
return hd;
}
What will be the impact if the above two MACROS are passed with Base and Derived class swapped?