Hiding class pointers -- was it a good idea?
Bill Baxter
dnewsgroup at billbaxter.com
Wed Aug 15 09:29:15 PDT 2007
Gregor Richards wrote:
> #1 advantage of making them always by-value: Ridiculously inconsistent
> use of by-value passing, ref passing and pointer passing.
>
> void foo(Thing a);
> void foo(ref Thing a);
> void foo(Thing *a);
>
> Wait, that's not an advantage at all, that's C++.
I don't get your point. Each of those things has different uses in C++.
// if Thing is small/PoD and you don't want changes to affect caller
void foo(Thing a);
// if Thing is bigger, you want to allow caller-visible changes, and you
require calling with non-null
void foo(ref Thing a);
// same as above, but you want to allow null too
void foo(Thing *a);
The ref-can't-be-null thing may not hold for D, but it's true of C++.
--bb
More information about the Digitalmars-d
mailing list