CORBA style was: [omniORB] CORBA::string_alloc(len) problem
Bjorn Wennberg
bjornw@tihlde.org
16 Jul 1999 15:15:11 +0200
David Riddoch <djr@uk.research.att.com> writes:
> On 16 Jul 1999, Bjorn Wennberg wrote:
>
> > I'm just curious about this :-)
> >
> > As far as I'm able to understand the behaviour of string_alloc - it returns
> > a character pointer not a new String_var class?
> >
> > Thus the assignment would be correct without temporary copying the String_var:
> >
> > 1. String_var SomeString(CORBA::string_alloc(100));
> > 2. String_var SomeString(new char[100]);
> > 3. String_var SomeString = CORBA::string_alloc(1000);
> > Number 1 and 2 are equal and uses the ctor:
> > String_var::String_var(char *p) { _data = p; }
> > Number 3 might use either the ctor or the assignment operator, which are equal:
> > String_var::operator = (char *p) { if (_data) string_free(_data); _data = p; }
>
> No - the right hand side is a String_var, not a char*, so we use:
>
> String_var::operator = (String_var&)
>
> And thus we *copy* the string rather than consume it.
I don't think so. What is the point with different ctor's if you can't use them?
One of the ctor takes a 'char *' as parameter - and according to my debugger,
it uses the ctor 'String_var::String_var(char *p)' when constructing the variable.
I'm not trying to be pedantic about anything - I just wanna know :-)
If the right-hand-side expression (CORBA::string_alloc(100)) returns a 'char *'
why shall it not use the ctor that takes a 'char *'?
bjornw>