Main Page | Report this Page
Computers Forum Index  »  Computer - Object (Corba)  »  [C++ Mapping] General question on using operator[] in...
Page 1 of 1    

[C++ Mapping] General question on using operator[] in...

Author Message
Jesse...
Posted: Tue Oct 21, 2008 1:51 pm
Guest
Hi,

I have a problem compiling a client using TAO. But, before I ask TAO
support, I raise the question as a general question on the C++ mapping, just
to be sure I comply with the spec.

IDL:
module ServiceModule {

typedef sequence<Object> SeqObj;

interface Service {
SeqObj list_objects();
};
};

C++:
ServiceModule::Service_var service = [...]

ServiceModule::SeqObj_var objList = service->list_objects();

CORBA::Object_ptr theObj = objList[0]; // assuming there is at least one
element in the sequence


The compiler (gcc) gives the following error on the line that uses
operator[] for the sequence _var:
Client.cpp:32: error: ISO C++ says that these are ambiguous, even though the
worst conversion for the first is better than the worst conversion for the
second:
/oasis-project/pdeparis/tao-1.5a/ACE_wrappers/build/Linux-2.6EL5/TAO/tao/Seq_Var_T.inl:208:
note: candidate 1: typename TAO_VarSeq_Var_T<T>::T_elem
TAO_VarSeq_Var_T<T>::operator[](CORBA::ULong) [with T =
ServiceModule::SeqObj]
Client.cpp:32: note: candidate 2: operator[](ServiceModule::SeqObj*, int)
<built-in>

I have had this error since quite a while now, through various major
versions of TAO (even Orbix 3 !), and got used to the work around:

CORBA::Object_ptr theObj = (*objList)[0];

However, I would like to be sure that this operator[] for sequence _var is a
a reality (included in the spec) and the way I use it is compliant.

Cheers,

JC.

PS: I cross-post on comp.soft-sys.ace since the activity on
comp.object.corba is very low (as an euphemism Wink
 
Jon Biggar...
Posted: Wed Oct 22, 2008 9:51 pm
Guest
Jesse wrote:
Quote:
CORBA::Object_ptr theObj = objList[0]; // assuming there is at least one
element in the sequence


The compiler (gcc) gives the following error on the line that uses
operator[] for the sequence _var:
Client.cpp:32: error: ISO C++ says that these are ambiguous, even though the
worst conversion for the first is better than the worst conversion for the
second:
/oasis-project/pdeparis/tao-1.5a/ACE_wrappers/build/Linux-2.6EL5/TAO/tao/Seq_Var_T.inl:208:
note: candidate 1: typename TAO_VarSeq_Var_T<T>::T_elem
TAO_VarSeq_Var_T<T>::operator[](CORBA::ULong) [with T =
ServiceModule::SeqObj]
Client.cpp:32: note: candidate 2: operator[](ServiceModule::SeqObj*, int)
built-in

I have had this error since quite a while now, through various major
versions of TAO (even Orbix 3 !), and got used to the work around:

CORBA::Object_ptr theObj = (*objList)[0];

However, I would like to be sure that this operator[] for sequence _var is a
a reality (included in the spec) and the way I use it is compliant.

That's an unfortunate side effect of the C++ overload resolution
mechanimsm. The problem is that '0' is an int, not a CORBA::ULong, so
there's two possible conversion paths:

A1. Convert 0 to CORBA::ULong
A2. call ServiceModule::SeqObj_var::operator[]()

and

B1. Convert ServiceModule::SeqObj_var to ServiceModule::SeqObj *&
B2. Convert 0 to CORBA::ULong
B3. call builtin operator[](ServiceModule::SeqObj *, int)

There's no way to make the compiler prefer the first one by the C++
rules, and conversion B1 is needed when passing a _var as an inout
parameter. This only happens when you use an integer constant as a
subscript.

Another workaround is this:

CORBA::Object_ptr theObj = objList[CORBA::ULong(0)];

or if you know CORBA::ULong is the same type as unsigned long:

CORBA::Object_ptr theObj = objList[0UL];


--
Jon Biggar
jon at (no spam) biggar.org
jon at (no spam) floorboard.com
 
 
Page 1 of 1    
All times are GMT
The time now is Fri Nov 27, 2009 9:40 pm