Overload bracket operators [] to get and set

前端 未结 2 1658
忘掉有多难
忘掉有多难 2020-12-13 03:43

I have the following class:

class risc { // singleton
    protected:
        static unsigned long registers[8];

    public:
        unsigned long operator [         


        
2条回答
  •  自闭症患者
    2020-12-13 04:16

    You need to return a reference from your operator[] so that the user of the class use it for setting the value. So the function signature would be unsigned long& operator [](int i).

提交回复
热议问题