, , QueryInterface A, QueryInterface C , QueryInterface C A . ,
QI(QI(A)->B)->C
QI(A)->C
. 4.3 , , , :
void AssertTransitive(ICar *pCar) { if (pCar) { IPlane *pPlane = 0; // request intermediate type of interface // HRESULT hr = pCar->QueryInterface(IID_IPlane, (void**)&pPlane); if (SUCCEEDED(hr)) { IBoat *pBoat1 = 0; // request terminal type of interface // hr = pPlane->QueryInterface(IID_IBoat, (void**)&pBoat1); if (SUCCEEDED(hr)) { IBoat *pBoat2 = 0; // request terminal type through the original pointer // hr = pCar->QueryInterface(IID_IBoat, (void**)&pBoat2); // if the following assertion fails, pCar // did not point to a valid object // , pCar // - assert(SUCCEEDED(hr)); pBoat2->Release(); } pBoat1->Release(); } pPlane->Release(); } }
QueryInterface , , , , - . , , QueryInterface. QueryInterface , " / " QueryInterface. , , . , QueryInterface .