Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

C++ programming practical question 10

  Shared By: Adah Miller    Date: Jan 24    Category: C++ Programming    Views: 95

Answer:

class opOverload{
public:
bool operator==(opOverload temp);
};

bool opOverload::operator==(opOverload temp){
if(*this == temp ){
cout<<"The both are same objects\n";
return true;
}
else{
cout<<"The both are different\n";
return false;
}
}

void main(){
opOverload a1, a2;
a1= =a2;
}


Answer :
Runtime Error: Stack Overflow


Explanation :
Just like normal functions, operator functions can be called recursively. This program just illustrates that point, by calling the operator == function recursively, leading to an infinite loop.

Share: 
 

Didn't find what you were looking for? Find more on C++ programming practical question 10 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: