[omniORB] Problem inserting an array of structs

Brian Neal bgneal at gmail.com
Tue Jan 10 08:21:56 GMT 2006


> From: Duncan Grisby <duncan at grisby.org>
> On Friday 6 January, Brian Neal wrote:
>
> > Test::TestStructArray_forany fa;
> > if (a >>= fa) {
> >    std::copy(&fa[0UL], &fa[0UL] + numElems,
> >                   std::ostream_iterator<Test::TestStruct>(std::cout, "\n"));
> > }
> >
> > Notice the 0UL. If I don't, and use plain old int 0 to index into the
> > forany, g++ 3.4.4 gives me the following error:
> >
> > main.cpp:46: 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:
>
> I don't know why gcc thinks it's ambiguous, but I've added the operators
> for int as for the fixed length struct case.
>

I'm not totally sure about this either, but here is my hunch. In
templatedecls.h, _CORBA_Array_Variable_Forany and
_CORBA_Array_Fix_Forany template classes have both operator T*() const
and operator[] operators. So when I index into a forany with an int
the compiler can't decide if it should apply the operator T*() and
then use the "built-in" indexing or operator[]. Indexing with an
unsigned long (CORBA::ULong) makes it clear I want operator[]....I
guess.

I don't know if g++ is right or wrong...I will go off and try this on
a few more compilers. Again, we are using g++ 3.4.4...I'd like to see
what 4.0 does. I'll try it on the Comeau compiler, which is lauded for
being very standard compliant. I may post on one of the c++ newsgroups
about this as well.

Thank you,
BN



More information about the omniORB-list mailing list