Property assign

Zarathustra adam.chrapkowski at gmail.com
Sat May 3 13:30:13 PDT 2008


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;
}


More information about the Digitalmars-d-learn mailing list