C++ (Qt)MyOpaqueRef * ref = CreateOpaqueRef(name);....// return; ???...DestroyOpaqueRef(ref);
C++ (Qt)#define RETURN_AND_DELETE_REF(ref) DestroyOpaqueRef(ref); return MyOpaqueRef * ref = CreateOpaqueRef(name);...RETURN_AND_DELETE_REF(ref);...RETURN_AND_DELETE_REF(ref) 0;
C++ (Qt)#define RETURN_AND_DELETE_REF(ref) DestroyOpaqueRef(ref, ...) DestroyOpaqueRef(ref); return __VA_ARGS MyOpaqueRef * ref = CreateOpaqueRef(name);...RETURN_AND_DELETE_REF(ref);...RETURN_AND_DELETE_REF(ref, 0);
C++ (Qt)struct CScoped_OpaqueRef { CScoped_OpaqueRef( OpaqueRef * ref ) : mRef(ref) {} ~CScoped_OpaqueRef( void ) { if (mRef) DestroyOpaqueRef(mRef); } operator OpaqueRef * ( void ) { return mRef; } void operator = ( OpaqueRef * ref ) { if (mRef != ref) { if (mRef) DestroyOpaqueRef(mRef); mRef = ref; } } private: OpaqueRef * mRef; CScoped_OpaqueRef( const CScoped_OpaqueRef & ref ) {} void operator = ( const CScoped_OpaqueRef & ref ) {}};
C++ (Qt)std::unique_ptr<OpaqueRef, DestroyOpaqueRef> ref = CreateOpaqueRef(name);