我正在尝试实现一次用于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)