QueryInterface()
-
Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss
-
Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss
-
Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss
skruss wrote: Why not just using static_cast as well? It's a matter of taste really. They exist so that you can tell the compiler what it is that you want to accomplish. That way, the compiler can issue warnings/errors if what you want to do is illegal. Of course, dynamic_cast is slightly different from the other casting operators in that it actually does the cast in runtime (it returns 0 if A is not assignable to B -
B* b = dynamic_cast<A*>
reinterpret_cast should be avoided unless you really need it. Why? Because it basically tells the compiler to cast whatever into whatever. The compiler can thus not issue any warnings/errors. -- Booohoo! -
if you find these words like static_cast,reintepret_cast and dynamic_cast on msdn you will find the answer. nice to meet u