重载运算符()与成员函数get()
Overloaded operator () vs member function get()
所以在我的代码中我有
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);
相关文章:
- C++中是否有任何函数等同于python中字典的get函数?
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 使用"push_back"作为带有"get"函数C++的向量
- 从 unique_ptr::get 发送指针作为指针引用进入函数
- c++ 在类中声明私有的向量,但有一个 get 函数
- c++为什么ifstream get()函数返回无法识别的特殊字符
- 使用Set/Get-like方法或GetSet组合函数
- 为什么 std::get<T> 其中 T 是调用 constexpr 函数失败的结果?
- 如何在输入成员函数中使用 get()
- C++ :: 设置值函数在函数内设置,但后跟 Get 函数,设置值消失了
- 为什么 ADL 不能使用 std::get 解析为正确的函数
- 在类中使用映射并通过其他类的 get() 和 set() 函数访问值
- C++11: 如何编写一个像 Get 一样工作的模板函数<tuple>...但是收到参数包?
- get 函数返回无效值
- cin.get()函数在C 中
- 通过引用将私有类实例传递到另一个类 C++ 的"get"函数中
- 类成员函数 get 不会返回值
- ifstream 函数"get"如何改变其字符参数?
- 重载运算符()与成员函数get()
- 输入流函数get在c++中