classes as out parameters

halfhphalfhp Nick FellowsOrganization: AoptixProject: optical comms applianceMember ✭✭
I have some classes defined in Slice like this: (Once again, I apologize for any syntax errors or typos)
class Command {...};

class Response {...};

class CommandSpec extends Command {...};

class ResponseSpec extends Response {...};

class MyModule {
    ...
    void sendCommand(Command cmd, out Response resp);
};


In my C++ code, I derive the above classes and attempt the following:

...
Ice::ObjectPrx base = mpIce->stringToProxy(...);
MyModulePrx mod = MyModulePrx::checkedCast(base);
...

mod->sendCommand(new CommandSpec(...), new ResponseSpec(...));

and I get something like the following error:
Error 2 error C2664: 'void IceProxy::MyModule::sendCommand(const CommandPtr &,ResponsePtr &)' : cannot convert parameter 2 from ResponseSpec *' to 'Response &'...

I can get around the problem by creating a ResponsePtr like this:
ResponseSpec r = new ResponseSpec(...);
ResponsePtr resp(r);

and calling sendCommand:
mod->sendCommand(new CommandSpec(...), resp);

OR...If I change the Slice signature of sendCommand command to:
void sendCommand(Command cmd, Response resp);

and change my C++ code specializations to reflect this change (by removing "const" from the resp parameter) then everything compiles.

I would like to simply pass in specializations of Response (such as ResponseSpec) without needing to first create a Ptr instance.

Is this doable? I know its probably something silly that I am not grasping here, but I just cant seem to figure this out.

Thanks,
Nick

Comments

  • dwaynedwayne St. John's, NewfoundlandDwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications EngineMember ✭✭✭
    Normally what you would do in this case would be something like the following:
    ResponsePtr resp;
    mod->sendCommand(..., resp);
    
    if(RespsonseSpecPtr::dynamicCast(resp))
    {
         // Handle ResponseSpec
    }
    else if(SomeOtherTypeDerivedFromResponsePtr::dynamicCast(resp))
    {
         // Handle that type
    }
    else etc...
    
    However I am not sure if this is what you mean to do. You mention wanting to pass in specializations. This is not possible with out paramaters. Out paramaters are not passed to the server, they are returned from the server. All the client passes is the Ptr type to hold the value that is returned from the server. It is up to the server choose which specialization is returned.
  • halfhphalfhp Nick FellowsOrganization: AoptixProject: optical comms applianceMember ✭✭
    That answers my question. Thanks Dwayne.
Sign In or Register to comment.