byval keyword to make objects act as value types

BC notmi_emayl_adreznot at hotmail.com.remove.not
Sun Dec 23 00:27:14 PST 2007


On Sun, 23 Dec 2007 07:52:06 -0000, BC  
<notmi_emayl_adreznot at hotmail.com.remove.not> wrote:

> On Sun, 23 Dec 2007 06:22:49 -0000, Craig Black <craigblack2 at cox.net>  
> wrote:
>
>>> so that 'byval MyClass' is a new type that acts like MyClass in all  
>>> ways (ie. is polymorphic) except that it gets dupped on non-const  
>>> assignment from other byval MyClasses and normal MyClasses. possibly  
>>> also on assignment to normal MyClasses. this would require that it  
>>> *has* a dup method, or maybe a copy constructor
>>>
>>> byval Base b = new Derived;
>>
>> I'm not really "getting" your proposal, but maybe I missed something.  
>> What's the novelty here?  Why not just add copy semantics to structs?   
>> Then you don't need the byval keyword anymore.
>>
>>> i notice the tango iterators are classes. surely we want to use  
>>> iterators as value types... this way, we can.
>>
>> I wholeheartedly agree, but why not use structs?
>>
>> -Craig
>
> well, there's inheritance. polymorphism. also there's not always a  
> definitive
> answer to whether a given data structure should be a value or reference
> type. this way, they can be both.

although adding those things and ctors/dtors to structs like you said
would be just as good really. i got the impression that option was off
the table though.
should struct member functions & dtors be virtual by default?



More information about the Digitalmars-d mailing list