Re: [GD-General] Multiple Inheritance and RTTI
Brought to you by:
vexxed72
From: brian s. <pud...@po...> - 2003-02-06 17:55:45
|
I think that might be too much of a simplification. The ability to dynamic_cast implies object identity. If I can dynamic_cast from InterfaceA * to InterfaceB *, I know that the pointer I'm holding points to an object that is both an InterfaceA * and a InterfaceB *. QueryInterface doesn't mandate that. If I query for InterfaceB* from an InterfaceA * pointer, I might get back a pointer that points to the same object as the InterfaceA *, like dynamic_cast would return. But I could very well get back a pointer to a completely different object; the object pointed to by InterfaceA * could just as well return a pointer to a InterfaceB* member (see my previous post re: aggregation). Why might I want to do that? A few reasons: 1) I can inherit the behavior of an InterfaceB implementation without having that implementation exposed to me at all. All I need is the definition of InterfaceB and a factory function that can create an object to implement InterfaceB for me. 2) I might want to delay creating an InterfaceB object until it's needed, if I know that it's heavyweight. All that COM requires of QueryInterface is (1) consistency: if you can get an interface once, you can always get it and (2) identity: if you can get an InterfaceB * from an InterfaceA *, you can go back to the InterfaceA * from the InterfaceB *. dynamic_cast goes further and implies an "is-a" relationship between InterfaceA and InterfaceB. --brian On Thursday, February 6, 2003, at 06:12 AM, Thatcher Ulrich wrote: > To try to cut through the terminology a little: > > COM == RTTI |