重载运算符()与成员函数get()

Overloaded operator () vs member function get()

本文关键字:函数 get 成员 重载 运算符      更新时间:2023-10-16

所以在我的代码中我有

double Matrix::get(int i, int j){
     return data[i][j];
}
double Matrix::operator()(int i, int j){
      return data[i][j];
}

问题是,在课堂之外,我可以打电话给

Matrix A;
A(i,j)

在课堂上,我不知道如何引用对象(A)所以

Matrix::somefunction(){
    this(i,j)  ???
}

我将如何引用调用对象?

你非常接近:

(*this)(i,j)

您也可以像一样调用

    operator()(i,j);

或(如前所述)

    (*this)(i,j);