| Re: Returning a Struct from a Function |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++ · Group Profile
Author: alex.j.k2alex.j.k2 Date: May 11, 2008 11:18
On May 11, 2:02 pm, john gmail.com> wrote:
>> Hello, newbie here.
>
>> I'd like to know if there is a way to return a structure from a
>> function, without creating any other intermediate variables. Also,
>> this should be done such that the function can still be declared as
>> inline.
>
> The usual way is to pass a reference to the struct (as a parameter) in
> which you want to put the return value (the same for vector, list, ...)
OK, that certainly works.
But is this the only way to do it?
What if I have a lot of code which returns a struct (or vector,
etc..) by creating an intermediate variable in the function; and I do
not want to modify all the occurrences of the function in the code,
only the function itself.
Can I eliminate the creation of the extra variable, while returning
the struct (but not as a parameter) ?
Also, thanks for the quick reply.
Alex
|