假设它作为成员重载,你通常会使用(*this)operator<parameter(s)>,所以如果一个类有一个重载operator[],比如一个int参数(例如T &operator[](int index);),另一个成员函数可以调用它(*this)[2].
如果它作为一个自由函数重载,你就会做同样的事情.例如,假设你有一个免费的功能,如:
my_string operator+(my_string const &a, my_string const &b);
Run Code Online (Sandbox Code Playgroud)
您可以从以下成员函数调用它:
my_string operator+(my_string const &other) {
return (*this) + other;
}
Run Code Online (Sandbox Code Playgroud)
可能在这种简单的案例中没用,但仍然显示了一般的想法.
| 归档时间: |
|
| 查看次数: |
93 次 |
| 最近记录: |