[omniORB] Problems with method returning a complex
structure
Sai-Lai Lo
S.Lo@uk.research.att.com
30 Jun 2000 16:48:09 +0100
Hi! There are several errors in your code. Try this:
updates * recordData_i::refresh()
{
updates_var Result = new updates();
recordSequence& rs = Result->recordUpdates;
rs.length(1);
rs[0].recordName = (const char *) "JIM";
fields& fs = rs[0].recordFields;
fs.length( 2);
fs[0].fieldName = (const char *) "NITTY GRITTY";
fs[0].value = (const char *) "HO-HO";
fs[1].fieldName = (const char *) "ARTHUR";
fs[1].value = (const char *) "POOP-POOP";
return Result._retn();
}
>>>>> Andy Weber writes:
> updates * recordData_i::refresh()
> {
> updates *Result; // has to be new'd!!
> // updates *Ans;
> Result = new updates();
Result-> recordUpdates = recordSequence();
> recordSequence& rs = Result->recordUpdates;
> rs[0].recordName = (const char *) "JIM";
> rs[0].recordFields = fields();
> fields& fs = rs[0].recordFields;
> fs.length( 2);
> fs[0].fieldName = (const char *) "NITTY GRITTY";
> fs[0].value = (const char *) "HO-HO";
> fs[1].fieldName = (const char *) "ARTHUR";
> fs[1].value = (const char *) "POOP-POOP";
> // Ans = new updates( *Result); // blows up
> // delete Result; // blows up
> // return Ans; // blows up
> return new updates( *Result); // has to be copied - why?? -
> // // Also leaks memory
> }
Try this:
--
Sai-Lai Lo S.Lo@uk.research.att.com
AT&T Laboratories Cambridge WWW: http://www.uk.research.att.com
24a Trumpington Street Tel: +44 1223 343000
Cambridge CB2 1QA Fax: +44 1223 313542
ENGLAND