Hiding class pointers -- was it a good idea?

Deewiant deewiant.doesnotlike.spam at gmail.com
Wed Aug 15 12:35:09 PDT 2007


Bill Baxter wrote:
> Deewiant wrote:
>> 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.

D'oh! Good point.

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

In accordance with my "d'oh" above, yes, that's what I meant. ;-)

-- 
Remove ".doesnotlike.spam" from the mail address.



More information about the Digitalmars-d mailing list