new principle of division between structures and classes
Bill Baxter
wbaxter at gmail.com
Sat Jan 10 14:55:59 PST 2009
2009/1/11 Christopher Wright <dhasenan at gmail.com>:
> Weed wrote:
>>
>> Denis Koroskin пишет:
>>
>>> I'd suggest you to state you ideas as simple and keep your posts as
>>> small as possible (trust me, few people like reading long posts).
>>
>> The extra-short formulation of my idea:
>> Objects should be divided on POD (struct) and non-POD (class).
>>
>> Instead of such division as now: POD && value type (struct) and POD &&
>> reference type (class).
>
> The reference versus value type difference is just a matter of defaults.
>
> Returning a class instance on the stack from a function is possible with
> inout parameters, though you can't use a constructor in that case:
>
> void main ()
> {
> scope MyClass obj = new MyClass;
> foo (obj);
> }
>
> void foo (inout MyClass obj)
> {
> // initialize obj somehow
> }
I don't think that does what you think it does.
Remember that obj is basically a pointer under the hood. So what that
'inout' does is allow you to make obj point to something else. You
don't need the 'inout' if all you want to do is change the contents of
what obj points to.
I think what 'scope MyClass obj' actually does is reserve the
appropriate amount of space on the stack somewhere, then make obj
point to that space instead of the heap. So that means you can still
reassign obj if you feel like it. And it can be reassigned to either
a scope or non-scope instance. It doesn't matter to obj because obj
is just a pointer.
--bb
More information about the Digitalmars-d
mailing list