Re: [GD-General] Multiple Inheritance and RTTI
Brought to you by:
vexxed72
|
From: Peter D. <pd...@mm...> - 2003-02-06 12:48:29
|
Gareth Lewin wrote:
>> Out of curiosity, can someone post a real example of using the
>> QueryInterface pattern (in performance-critical code)?
>
> QueryInterface is fairly quick. A lot depends on the number of
> interfaces you are implementing per object.
>
> But most things use macros like
>
> (note, this is psuedo code.)
>
> START_INTERFACELIST
> ADD_INTERFACE(IID_IRender)
> ADD_INTERFACE(IID_IFoo)
> END_INTERFACELIST
>
> which becomes somethinglike
>
> bool QueryInterface(GUID iid, void** ppObject)
> {
> if (iid == IID_IRender)
> {
> (*ppObject) = reinterpret_cast<void*>(this);
> return true;
[...]
Thanks. :-)
But I asked for a real example (read taken from a real project) of using
(not implementing) the QI pattern, an example that demonstrates the
superiority of QI over the alternatives.
FWIW, for the QI implementation, I prefer a dynamic_cast-style interface:
if(IRenderable * p = queryInterface<IRenderable>(q))
{
// do stuff
}
(when I feel like reinventing dynamic_cast at all, that is.)
|