小编che*_*hen的帖子

C++运算符[]

我正在尝试实现一次用于Set的运算符[]和一次用作Get,我需要区分这两种情况,就像get的情况一样,如果返回的值相等,我需要抛出一个异常到-1; 而在Set i的情况下,只需覆盖该值.appple [2] = X; Y =苹果[2];

我不知道如何区分这两种模式,我的功能签名是:

   double& Security::operator[](QuarterType index){
    if(index<0 || index>MAX_QUATERS){
        throw ListExceptions::QuarterOutOfBound();
    }
    return evaluation[index].getValueAddress();
   }
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading c++11

4
推荐指数
2
解决办法
374
查看次数

标签 统计

c++ ×1

c++11 ×1

operator-overloading ×1