C++ 称为无限的算子函数

C++ 称为无限的算子函数,c++,C++,我得到了运行时错误,有人能找出为什么在这个程序中有一个无限调用,以及哪一行正在执行它吗 这是我的密码 class opOverload{ public: bool operator==(opOverload temp){ if(*this == temp){ cout << "both same"; return true; } else{ cout &l

我得到了运行时错误,有人能找出为什么在这个程序中有一个无限调用,以及哪一行正在执行它吗

这是我的密码

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){

cout因为
*this==temp
相当于
(*this).operator==(temp)
,它显然调用了您刚才编写的相同的
operator=

*this == temp
将再次调用运算符重载,因此您基本上正在执行:

A(){
   A();
}

这是一个自递归函数调用,您显然没有取得进展(朝向基本情况,更糟糕的是……没有基本情况)

你认为这个==temp
会调用什么?安装一个调试器本可以解决这个问题。事实上,我的大脑在过去15个小时的持续学习中感到疲劳,所以无法理解你是如何证明它是无限调用的?ideone中出现运行时错误,这主要发生在infinte调用上