|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - 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 03 2008
Add this in class C:
B b(ubyte b_) {_b = b_;}
-Steve
May 04 2008
|