Archived
This forum has been archived. Please start a new discussion on GitHub.
How I can cast Ice::ObjectPrx to my own interface?
in Help Center
For the sake of simplicity, I'll use the interface of your example. So, we have:
For example, I can't do smth like this:
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
0
Comments
-
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.0 -
Oh, thanks a lot, Benoit! It actually what I need!0