Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-04-23 11:33:07


Not entirely, passing a pointer doesn't tell you that the parameter will
change, it just tells you that it might, it still leaves you in the position
of having to track down the function and check it. But outside of that, if
you're like me, at this point you prefer references to pointers, whenever
possible.

----- 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

> Justin M. Lewis wrote:
> > I don't really know how this works. I know someone who's a big Boost
> > fan, and he said he didn't know of anything like what I'm going to
> > propose exists in Boost here. So, here it is.
> >
> > The problem I was having, we have references, that allows me to pass a
> > paramter to a function, that function modifies the value passed in, at
> > the point where that function is called, I cannot tell that the data is
> > being modified. Basically, it leads to somewhat confusing code,
> > especially in a case where you're looking at someone else's code trying
> > to track down where a value gets set.
> >
> > void func(int &x){x = 1977;};
> >
> > void blah()
> > {
> > int y=0;
> > func(y);
> > func2(y);
> > printf("%d\n", y);
> > }
> >
> >
> > Something along those lines could become confusing, obviously in a much
> > larger program.
> >
> > My idea was, if you make a simple template class, originally I called it
> > CRetVal, you could force people to specify at the time the function is
> > called what's going on. I made a helper template function retval that
> > would create and return a CRetVal object of the desired type to save
> > from needing to use template notation in line all over the place. So,
> > the above would become something more like.
> >
> > void func(CRetVal<int> x){x = 1977;};
> >
> > void blah()
> > {
> > int y=0;
> > func(retval(y));
> > func2(y);
> > printf("%d\n", y);
> > }
>
> could you not get the same effect by using
> void func(int* px) {*px = 1977;}
>
> int y = 0;
> func(&y);
> func2(y);
>
> Vin
>
>
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk