称为Infinite的运算符函数
Operator Function Called Infinite
我得到运行时错误,谁能弄清楚为什么在这个程序中有一个无限调用,哪一行正在做它
http://ideone.com/0CWZTD这是我的代码
class opOverload{
public:
bool operator==(opOverload temp){
if(*this == temp){
cout << "both same";
return true;
}
else{
cout <<"both different";
return false;
}
}
};
int main() {
// your code goes here
opOverload a1,a2;
a1==a2;
return 0;
}
因为*this == temp
等于(*this).operator==(temp)
,它显然调用了您刚才写的相同的operator==
*this == temp
将再次调用你的操作符重载,所以你基本上是在做:
A(){
A();
}
这是一个自我递归函数调用,你显然没有取得进展(向基本情况,甚至更糟…
相关文章:
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 重载运算符new[]的行为取决于析构函数
- 构造函数和转换运算符之间的重载解析
- C++ STD 函数运算符:有没有一种方法可以通过函数将一个向量映射到另一个向量上?
- 是什么让一些命名函数/运算符与众不同?
- 删除了所有自动生成的构造函数/运算符的类仍然可以从函数返回吗
- 如何在局部类中定义友元函数运算符>>?
- 隐式转换和函数运算符
- 如何从函数运算符(x,y)返回向量元素的引用
- C++/析构函数-运算符删除
- 获取函数运算符<未定义的引用
- VS2012 std::函数运算符 bool 意外返回 true
- "Polymorphic"非成员函数/运算符,是否需要额外的重载?
- Xcode - 控制到达非无效函数运算符错误的末尾
- 重载类函数运算符兼任二传手和吸气手
- 为简单结构定义哪个复制/移动构造函数/运算符
- 关于函数/运算符重载的困惑
- 函数运算符上的未定义引用>>
- C++ 重载函数运算符和继承,无法在子类函数中正确使用它
- 如何使用另一个类的重载函数运算符(operator())