[omniORB] basic parameter passing question
Duncan Grisby
duncan at grisby.org
Thu Dec 1 23:12:20 GMT 2005
On Wednesday 30 November, Anthony Shipman wrote:
> isdn::BChannelControlClient_var ctlObj_;
>
> isdn::BChannelControlClient_var&
> BChannel::getControl()
> {
> return ctlObj_;
> }
You should never ever return _var types or references to them. If you
do, you'll only confuse things. _vars should only be used as holders for
local variables and member variables. For return values, only use _ptr
types.
> A method of an interface wants to return this object reference.
>
> isdn::BChannelControlClient_ptr
> Service_impl::new_client(...)
> {
> ...
> return isdn::BChannelControlClient::_duplicate(bchan->getControl());
> }
I think what's going on here is that your compiler is generating a
temporary _var instance as part of the _duplicate call, and therefore
messing up the reference count. That's part of the reason you shouldn't
return references to _vars. If you make your getControl() method return
a BChannelControlClient_ptr and do the _duplicate in getControl(),
everything will work as you expect.
Cheers,
Duncan.
--
-- Duncan Grisby --
-- duncan at grisby.org --
-- http://www.grisby.org --
More information about the omniORB-list
mailing list