May 03, 2008 Property assign | ||||
---|---|---|---|---|
| ||||
How to overload assing to property ? ___________________________________________________ enum A : ubyte{ A1, A2 } struct B{ ubyte b1; ubyte b2; ubyte b3; void opAssign (A a){ b1 = a; } } class C{ private: ubyte _a; B _b; public: ubyte a(ubyte a_){ return _a = a_; } // ubyte a(ubyte a_){ return _a = a_; } <- It works // but it's uncomfortable ubyte a( ){ return _a ; } B b(B b_){ return _b = b_; } B b( ){ return _b ; } } int main(){ B objB; C objC = new C; objB = A.A1; // it's OK objC.b = A.A1; // error :( objC.b = objB; // it's OK objC.b = B(A.A1) // it's OK return 0; } |
May 04, 2008 Re: Property assign | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zarathustra | Add this in class C: B b(ubyte b_) {_b = b_;} -Steve |
Copyright © 1999-2021 by the D Language Foundation