, QueryInterface , , . ,
QI(A)->A
.
. 4.4 :
void AssertReflexive(ICar *pCar) { if (pCar) { ICar *pCar2 = 0; // request same type of interface // HRESULT hr = pCar->QueryInterface(IID_ICar, (void**)&pCar2); // if the following assertion fails, pCar // did not point to a valid object // , pCar // assert(SUCCEEDED(hr)); pCar2->Release(); } }
, ICar QueryInterface ICar ICar. , :
extern void GetCar(ICar **ppcar); extern void UseVehicle(IVehicle *pv); ICar *pCar; GetCar(&pCar); UseVehicle(pCar); // ICar-ness is syntactically lost // ICar- void UseVehicle(IVehicle *pv) { ICar *pCar = 0; // try to regain syntactic ICar-ness // ICar- HRESULT hr = pv->QueryInterface(IID_ICar, (void**)&pCar); }
, UseVehicle, , ICar, , (counterintuitive), .
, QueryInterface , , , " / " QueryInterface. , ( ) (explicit) . . 4.5 . , , .