Thread: Ambiguity issue

  1. #16
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi CornedBee,


    Do you mean in COM, except downcast, other casts are not allowed, it is for COM provider developer for for COM client developer?

    If you mean for COM client developer, I can understand.

    If you mean for COM provider developer, I do not agree. You can see in COM aggregation model, in the inner component, we will use reinterpret_cast to convert unmanged unknown interface to IUnknown interface.

    Quote Originally Posted by CornedBee View Post
    Because the cast relies on knowledge you're not supposed to have.

    regards,
    George

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by George2 View Post
    Do you mean in COM, except downcast, other casts are not allowed, it is for COM provider developer for for COM client developer?
    The client developer.

    You can see in COM aggregation model, in the inner component, we will use reinterpret_cast to convert unmanged unknown interface to IUnknown interface.
    I see no reason for any COM implementation ever to use reinterpret_cast.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi CornedBee,


    1.

    Quote Originally Posted by CornedBee View Post
    The client developer.
    Client developer only need to invoke QueryInterface. Why need to manually downcast manually?

    2.

    Quote Originally Posted by CornedBee View Post
    I see no reason for any COM implementation ever to use reinterpret_cast.
    I have attached the code for aggregation model from Inside COM book about how reinterpret_cast is used. Please refer to,

    CB::NondelegatingQueryInterface (CMPNT2.cpp)


    regards,
    George

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The cast there is
    1) unnecessary (static_cast would suffice)
    2) unnecessary (you could just cache the pointer)
    3) unnecessary (the pointer is a copy of this anyway).

    Well, except for the whole fake IUnknown business. Now that is ugly ...
    I can't believe that's the best way to implement aggregation.

    Why need to manually downcast manually?
    Not saying he needs to. Just that it's the only cast allowed.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi CornedBee,


    1.

    In my knowledge of implementation of aggregation model, since a class can not give two different implementation of an interface, we have to name unmanaged IUnknown interface to some other value, like INondelegatingUnknown in this case, and using the same function table of interface IUnknown (QueryInterface/AddRef/Release).

    To get the actual unmanaged interface (INondelegatingUnknown) as IUnknown interface, the only way we could do is,

    IUnknown *pI = reinterpret_cast<IUnknown*>(static_cast<INondelega tingUnknown*>this);

    If you have found better way, it is appreciated if you could share here.

    Quote Originally Posted by CornedBee View Post
    The cast there is
    1) unnecessary (static_cast would suffice)
    2) unnecessary (you could just cache the pointer)
    3) unnecessary (the pointer is a copy of this anyway).

    Well, except for the whole fake IUnknown business. Now that is ugly ...
    I can't believe that's the best way to implement aggregation.
    2.

    Quote Originally Posted by CornedBee View Post
    Not saying he needs to. Just that it's the only cast allowed.
    Downcast means cast from base to derived, upcast means cast from derived to base. QueryInterface will always cast this to sub-objects, so I think it should be upcast. Right?


    regards,
    George

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Downcast means cast from base to derived, upcast means cast from derived to base. QueryInterface will always cast this to sub-objects, so I think it should be upcast. Right?
    Could well be. I can never remember which is which.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #22
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks all the same, CornedBee!


    When you happen to find in the future about both upcast/downcast samples in QueryInterface, please let me know here. :-)

    Quote Originally Posted by CornedBee View Post
    Could well be. I can never remember which is which.

    regards,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. type safe issue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:32 PM
  3. Ambiguity error with double as parameter type
    By tejasvsrinivasa in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2007, 04:17 PM
  4. directsound issue
    By valis in forum Tech Board
    Replies: 0
    Last Post: 06-25-2006, 09:28 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM