From: Noel Yap (Noel.Yap_at_[hidden])
Date: 2003-05-03 19:55:27
"Justin M. Lewis" wrote:
> > If you wrote the function, why did you write it taking in a pointer if
> > the intent is not an in/out parameter?
> Maybe you're in a place where you just had to work with pointers. It
I still don't understand. Do you intend to rewrite the function
> > Can you explain or elaborate what you mean by "using pointers", please?
> using pointers, it seems pretty self explanatory to me.
> myfunc(const obj *ptr);
> If you're not dealing with something where you know you have allocated data
> floating around, you should use a reference.
> myfunc(const obj &ptr);
Wouldn't this still be dynamically allocated memory:
obj* ptr = new obj();
myfunc( *ptr );
> But, like I said, there are cases where you have to allocate data. So, how
> do you differentiate calls like
> myfunc1(const obj *ptr)
> myfunc2(obj *ptr) ?
void myfunc1( boost::dumb_ptr< obj const > ptr );
void myfunc2( boost::dumb_ptr< obj > ptr );
> I mean, if you just put dumb_ptr in place of both, how is it any different?
Because the type with which dumb_ptr is parameterized is different
thereby creating different types.
> How can you tell one from the other, without looking up the prototype?
boost::dumb_ptr< obj > in_out;
boost::dumb_ptr< obj const > in;
myfunc1( in_out ); // compiler error; if you want to pass in/out
parameters into in slots, there can be a conversion operator
myfunc2( in ); // compiler error
> I'm just saying, passing by pointer doesn't explicitly tell you anything,
> whereas, c_out and c_in_out do.
IMHO, it does. Like I said, they are just syntactic differences between
the two styles (except for the NULL situation).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk