When implementing IUnknown::QueryInterface() in C ++, there are several caveats with pointer manipulations. For example, when a class implements several interfaces (multiple inheritance) explicit upcasts are needed :
class CMyClass : public IInterface1, public IInterface2 { };
The reason for increasing efficiency is pretty obvious in multiple inheritance scenarios. However, everyone here and there I also see the following:
static_cast<IUnknown*>( *ppv )->AddRef();
instead of just calling AddRef() from within QueryInterface() .
Is there some reason why I should convert the value previously copied to ppv and not just call AddRef() for the current object?
source share