On Mon, 6 Dec 2010 13:44:41 -0500 Michel Fortin <[email protected]> wrote:
> On 2010-12-06 13:35:27 -0500, Andrej Mitrovic > <[email protected]> said: > > > Actually I really like the optional usage of ref here because it might > > help to disambiguate between a class and a struct object: > > > > E.g.: > > > > class Foo > > { > > } > > > > struct Bar > > { > > } > > > > void main() > > { > > Foo ref foo; // I can be sure Foo is a class > > Bar bar; > > } > > > > Sometimes it happens that I forget to 'new' a class object, and to the > > naked eye the code doesn't appear wrong, but using the optional ref > > keyword helps in tracking this kind of bug down. I guess the compiler > > should throw an error in cases where Foo is a struct. > > It does (throw an error in cases where Foo is a struct). I never though > of this usage. :-) > > Since we're speaking of the optional use of 'ref', here's a little quiz: > > alias Object A; > alias Object ref B; > > A ref a; > B ref b; > > What happens here? Should there be an error somewhere? Where? Also, > what happens if we apply different modifiers at different places? As I understand the (non-)semantics of 'ref', there should be no error. This code should considered by the compiler as equivalent to: Object a; Object b; Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com
