Monday, January 21, 2008

How to use interface correctly?

A: IparentInterface;
B: IchildInterface;

This code will generate error:

B: = IchildInterface (A); ==> will generate expected error whenever we access to B. At the time we down-cast A, we do not have exception.

The correct code should be:

A.QueryInterface (IchildInterface, B);

So the lesson here: Always use QueryInterface when you want to access other inteface of the same object. Do not cast Interface except you really know what you do.

No comments:

Google