Suggestion: properties should be treated as 'virtual members variables'

Kristian kjkilpi at gmail.com
Tue Sep 5 04:52:39 PDT 2006


In digitalmars.D.announce there has been discussion about why you cannot  
use properties as data members. For example, why the following (simple)  
example doesn't work:

class A {
     int prop() {return m_val;}
     int prop(int val) {return m_val = val;}

     int m_val = 0;
}

void f(inout int x) {
     x++;
}

void func() {
     A a = new A;

     f(a.prop);  //error: ((a).prop)() is not an lvalue
}


I think properties should work just like they were data members:  
everywhere you could give a data member you can also give a property. So,  
for example, the following should also work:

a.prob++;
a.prob -= 10;

Hence the implementation of 'prob' will be hidden from the user.

I would very much see properies as a 'virtual member variables'.


Hmm, would it be simplier to implement properties by using virtual tables  
for variables?...

(What object oriented languages did for functions, D does it for  
variables! *grin*)



More information about the Digitalmars-d mailing list