Having quite a few interfaces in my code, I wanted to encapsulate repeating Release
code in another method and not in a macro because this is C++ and I hate using macros. My initial attempt was to write a method such as
void SafeRelease(IUnknown **ppInterface) {
if(*ppInterface) {
(*ppInterface)->Release();
(*ppInterface) = nullptr;
}
}
however applying this method to a IDirect3DSurface9 *
e.g. like SafeRelease(&mySurface)
yields the error IDirect3DSurface9 **
is incompatible with IUnknown **
.
- What am I doing here wrong?
- Is there a better approach (hopefully not using macros) to implement such a function?