Is it possible to overload [] operator to do different thing in C++

I want to overload "[]" witch is used to access array

But I also want to separate read/write to do different thing

For example :

class myclass{
private:
    int val;
public:
    myclass(){val=0;}
    myclass(int _in){val=_in;}
    ....
    //for A=myclass[n]
    myclass& operator[](int index){
        ...
        return 
    }
    //for myclass[n]=B
    myclass& operator[](int index){
        ...
        return 
    }
}

Source: Windows Questions C++

LEAVE A COMMENT