Skip to content

Instantly share code, notes, and snippets.

@nootanghimire
Created April 8, 2014 12:22
Show Gist options
  • Save nootanghimire/10116447 to your computer and use it in GitHub Desktop.
Save nootanghimire/10116447 to your computer and use it in GitHub Desktop.
UnEthical Overloading
#include <iostream>
class ovt {
private:
int num;
public:
ovt(int n = 1):num(n){}
operator int(){
return num;
}
ovt operator+(ovt o){
return (num-o.num);
}
};
int main(){
ovt o1(10), o2(5);
std::cout<<static_cast<int>(o1+o2)<<std::endl;
return 0;
}
@shashikhanal
Copy link

Ah, yes! I hadn't think about default parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment