byval keyword to make objects act as value types

BC notmi_emayl_adreznot at hotmail.com.remove.not
Sat Dec 22 23:52:06 PST 2007


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.



More information about the Digitalmars-d mailing list