Created
April 8, 2014 12:22
-
-
Save nootanghimire/10116447 to your computer and use it in GitHub Desktop.
UnEthical Overloading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
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
We studied this one, you can change the logic but that's discouraged and there can't be any default parameters