重载双括号函数并在同一类中使用它
Overloading the Double Parentheses function and using it inside the same class?
我重载双括号函数并将其用于 C++ 中的矩阵的同一类中?我相信我正确地超载了它,但我不知道如何从内部调用它。
我假设你的双括号函数是operator()
,那么你可以通过两种不同的方式从其他成员函数内部调用它:
unsigned operator()(unsigned i) const
{
if(i == 0) return 1;
return operator()(i-1);
}
或
unsigned operator()(unsigned i) const
{
if(i == 0) return 1;
return (*this)(i-1);
}
相关文章:
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 如何使用connect将qml按钮与同一类的cpp函数连接起来
- 类成员函数无法访问同一类的私有结构节点?
- 无法将指向类的成员函数的函数指针作为参数传递给同一类的另一个成员函数
- 在 c++ 中将对象设置为等于同一类的构造函数是否有效?
- 如何将一个类的成员函数用作另一类的友元函数
- 如何获取同一类函数中类成员的函数指针?
- 一类嵌套类不能用作模板函数类型名
- 在多个文件中与同一类分开函数
- 将1D或2D向量传递给同一类的构造函数
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 让构造函数在其初始化列表中调用同一类的另一个构造函数是否有效
- 如何将两个类成员函数与同一类中的另一个函数一起添加
- 在C++中,类是否可以包含指向构造函数中初始化的同一类的指针?
- C 使用来自另一类的函数
- 如何为同一类对象的成员函数保留单独的变量副本?
- 如何将成员函数用于同一类的不同对象
- 为什么一个非平凡的成员需要为同一类中的匿名联合定义构造函数
- 我无法使用类变量作为同一类函数的默认参数