Home Help Center

How I can cast Ice::ObjectPrx to my own interface?

renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
For the sake of simplicity, I'll use the interface of your example. So, we have:
module Demo {
interface Printer {
void printString(string s);
};
};
After compiling this Slice definition to C++, the following typedef will be defined:
typedef ::IceInternal::ProxyHandle<::IceProxy::Demo::Printer> PrinterPrx;
On the other hand, our Demo::Printer is inherited from the Ice::Object and we have:
typedef ::IceInternal::ProxyHandle<::IceProxy::Ice::Object> ObjectPrx;
But I don't understand why I can't cast the PrinterPrx to ObjectPrx and vice versa. Is there any way to do this?
For example, I can't do smth like this:
Demo::PrinterPrx printer;
Ice::ObjectPrx object = reinterpret_cast<Ice::ObjectPrx>(printer); // error
// or vice versa
Ice::ObjectPrx object;
Demo::PrinterPrx printer = reinterpret_cast<Demo::PrinterPrx>(object); // error

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    You need to use generated uncheckedCast or checkedCast static methods instead.

    With your example:
    // C++
    
    Demo::PrinterPrx printer;
    Ice::ObjectPrx object = printer; // No need for a cast here
    
    Ice::ObjectPrx object;
    Demo::PrinterPrx printer = Demo::PrinterPrx::uncheckedCast(object);
    

    See the Ice demos and manual for more information.

    Cheers,
    Benoit.
  • renzorenzo Member Aleksey BlokhinOrganization: JSC "SRI Vector"Project: Remote host monitoring system
    Oh, thanks a lot, Benoit! It actually what I need!
Sign In or Register to comment.