Hiding class pointers -- was it a good idea?
Bill Baxter
dnewsgroup at billbaxter.com
Wed Aug 15 10:50:11 PDT 2007
Deewiant wrote:
> I don't see the consistency problem between stack and heap allocation.
>
> In fact, upon further reflection, what heap allocation has going for it is that
> it's more consistent: you can do "Obj o = new Obj" followed by a "return o", and
> it works, just as you can do "int x = 5" followed by "return x". If stack
> allocation were the default, "return o" would be a problem, because it's a
> pointer to the now-invalid stack.
...unless storing as 'scope'. But anyway, I'm not sure what you mean:
if by-value were the default, then 'return o' would return a copy of 'o'
not a pointer to it. And even if it did return a pointer to it, it's no
different than trying to return a pointer to a scope class, or to any
other function-local data. So maybe you mean "more safe" rather than
"more consistent"?
--bb
More information about the Digitalmars-d
mailing list