Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-04-23 17:10:52

It's not always that easy to give a function a name that will tell you
at invocation time which of it's parameters it's planning on changing,
and, it would be hard to tell people through just a function name that a
parameter is an in/out parameter.

As for a function returning a single param, I agree, normally you'd just
return it, UNLESS it's some big structure you don't want being copied
all over the place, then passing it by reference to a function makes
more sense.

Or, in the case I originally created this for, I had a function that
initialized an object to begin a transaction, I wanted to pass an object
into my function, and have it properly initialized to start a
transaction. Anyway, in that case, InitRequest makes it pretty clear
that the object being passed is going to be modified, but by making it a
c_out param, there's NO question, it's explicit at the invocation.

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Bo Persson
Sent: Wednesday, April 23, 2003 11:32 AM
To: boost_at_[hidden]
Subject: [boost] Re: Re: class proposal

"Justin M. Lewis" <boost_at_[hidden]> skrev i meddelandet
> Not entirely, passing a pointer doesn't tell you that the parameter
> change, it just tells you that it might, it still leaves you in the
> of having to track down the function and check it. But outside of
> you're like me, at this point you prefer references to pointers,
> possible.

The obvious solution is of course to name the function so that you can
what is does! :-)

A function returning a single value, should really RETURN the value and
update a parameter:

y = year_of_first_marriage();

Having a function lying about its purpose should be caught at its
definition, not at each call of the function:

void will_never_change_any_parameters_honest(int& x) { x = 7; }

is easy to catch early. :-)

Bo Persson

> ----- Original Message -----
> From: "Vincent Finn" <vincent.finn_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Wednesday, April 23, 2003 2:09 AM
> Subject: [boost] Re: class proposal
> > >
> > > void func(int &x){x = 1977;};
> > >
> > > void blah()
> > > {
> > > int y=0;
> > > func(y);
> > > func2(y);
> > > printf("%d\n", y);
> > > }
> > >

Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at