Public variables inside interfaces
Olivier Pisano
olivier.pisano at laposte.net
Sat Apr 30 05:56:25 PDT 2011
Hi,
You can "disguise" method calls into variables by using the @property tag.
interface Sizeable
{
// Getter
@property int size();
// Setter
@property int size(int s);
}
class A : Sizeable
{
int m_size;
public:
this()
{
}
@property int size() { return m_size; }
@property int size(int s) {return m_size = s; }
}
static void main(string[] args)
{
A a = new A();
a.size = 20; // calls a.size(int);
int i = a.size + 10; // calls a.size()
}
Cheers,
Olivier.
More information about the Digitalmars-d
mailing list