[omniORB] Question on operator <<= of class CORBA::Any

Sai-Lai Lo S.Lo@orl.co.uk
20 Oct 1998 16:35:06 +0100


>>>>> Zurek, Jan writes:

> Please have a look at the definition the following operator of class Any:
> 	void operator<<=( const char*& s );

> Is there a reason why the "s" is declared as reference?
> The HP-Compiler (aCC A.01.15) gives an error when compiling a code like the
> following because the value passed as reference is not an lvalue:

> const char* getit() { return "dodo" };

> CORBA::Any myAny;
> nyAny<<=getit;


> When changing the parameter "s" in the operator from "const char*&" to
> "const char*" everything (including the examples) compiles fine!


class Any {
  ...
 	void operator<<=( const char*& s );
};

Thanks for pointing this out. This is a bug (blush)!! The correct signature
should be:

        void operator<<=( const char* s);

Don't just change the signature in the header, you have to change its
implementation as well (file: src/lib/omniORB2/any.cc).


The reason why we do not catch this mistake is because all our regression
tests use from_string to ensure the correct operator is picked up.

For example:

const char* getit() { return "dodo" }

CORBA::Any myAny;

myAny <<= CORBA::Any::from_string((char*)getit(),0);

You may want to do this as well to make it obvious in your code that you
are inserting an unbounded string (or may be a bounded string in other
cases).

Regards,

Sai-Lai



-- 
Dr. Sai-Lai Lo                          |       Research Scientist
                                        |
E-mail:         S.Lo@orl.co.uk          |       Olivetti & Oracle Research Lab
                                        |       24a Trumpington Street
Tel:            +44 223 343000          |       Cambridge CB2 1QA
Fax:            +44 223 313542          |       ENGLAND