Archived
This forum has been archived. Please start a new discussion on GitHub.
Going from "in" to "out" param, using a class as a union
Hi!
Given the following slice defs:
class A {...}; // no methods
class B extends A {...}; // no methods
class C extends A {...}; // no methods
interface IceIsCool {
bool Wow(A);
};
I am using the A class as a "union", because in my code I instantiate objects of say type BPtr , and make proxy calls like
MyIceIsCoolPrx->Wow(myBPointerObject);
In the implementation of the Wow operation, on the server side, I am doing a BPtr::dynamicCast(myAPtrParameter) in order to access all of B's members. Everything worked fine until I realized I would like to make the parameter to the Wow operation an "out" parameter.
So I changed my slice definitions to
class A {...}; // no methods
class B extends A {...}; // no methods
class C extends A {...}; // no methods
interface IceIsCool {
bool Wow(out A);
};
and in my implementation of the IceIsCoolI class I removed the const keyword from the operation's signature to make it compliant with the slice2cpp's output.
When I recompile now, I get an error message because the compiler expects an object of type APtr as a parameter to the MyIceIsCoolPrx->Wow(myBPointerObject); call.
So my question is, why was it OK to pass an object of type BPtr to the operation call when it had an "in" parameter and it is not OK when the parameter is declared as an "out" parameter? A call like MyIceIsCoolPrx->Wow(APtr::dynamicCast(myBPointerObject)); doesn't help either.
Thanks
Catalin
Given the following slice defs:
class A {...}; // no methods
class B extends A {...}; // no methods
class C extends A {...}; // no methods
interface IceIsCool {
bool Wow(A);
};
I am using the A class as a "union", because in my code I instantiate objects of say type BPtr , and make proxy calls like
MyIceIsCoolPrx->Wow(myBPointerObject);
In the implementation of the Wow operation, on the server side, I am doing a BPtr::dynamicCast(myAPtrParameter) in order to access all of B's members. Everything worked fine until I realized I would like to make the parameter to the Wow operation an "out" parameter.
So I changed my slice definitions to
class A {...}; // no methods
class B extends A {...}; // no methods
class C extends A {...}; // no methods
interface IceIsCool {
bool Wow(out A);
};
and in my implementation of the IceIsCoolI class I removed the const keyword from the operation's signature to make it compliant with the slice2cpp's output.
When I recompile now, I get an error message because the compiler expects an object of type APtr as a parameter to the MyIceIsCoolPrx->Wow(myBPointerObject); call.
So my question is, why was it OK to pass an object of type BPtr to the operation call when it had an "in" parameter and it is not OK when the parameter is declared as an "out" parameter? A call like MyIceIsCoolPrx->Wow(APtr::dynamicCast(myBPointerObject)); doesn't help either.
Thanks
Catalin
0
Comments
-
Consider your server would return a C, and not a B. In this case, you would try to assign a C to a B. So this cannot work. You can only use:
APtr a; MyIceIsCoolPrx->Wow(a); BPtr b = BPtr::dynamicCast(a);
I.e., Ice cannot implicitly downcast.0