"extending" existed class
novice2
sorry at noem.ail
Wed Oct 18 03:02:14 PDT 2006
Hello.
I have existed class (for example Stream in phobos), and i need add
new method to it. In the past (if i correctly remember), i was able
to do it by defining function, that accept instance of class as
first argument, and then use it function like instance.function()
Now (DMD 1.70) i can't compile this code:
//////////////////////////////
class A
{
int method1() { return 1; }
}
int method2(A a)
{
return 2;
}
void main()
{
A a = new A;
int i = a.method1();
int k = a.method2();
}
//////////////////////////////
Compiler say
1.d(20): no property 'method2' for type '1.A'
Can anyone say, what i missed, or the better way to "extend"
existed class without declare new class based on existed?
Thanks.
More information about the Digitalmars-d-learn
mailing list