I am getting runtime error, Could anyone figure out why there is an infinite call in this programme and which line is doing it
Here goes my Code
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
will again invoke your operator overload, so you are basically doing:
A(){
A();
}
This is a self recursive function call, and you are obviously not making progress (towards the base case, even worse...there is no base case)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.