Created
April 16, 2016 17:47
-
-
Save XanClic/5adeb1c4dc6c3513834c819682ad46ec to your computer and use it in GitHub Desktop.
This file contains 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 <cstdio> | |
class Foo { | |
public: | |
Foo(int x): v(x) {} | |
Foo(const Foo &f) = delete; | |
Foo &operator>> (int x) { v >>= x; return *this; } | |
Foo &operator>>=(int x) { v >>= x; return *this; } | |
operator int(void) const { return v; } | |
private: | |
int v; | |
}; | |
int main(void) | |
{ | |
Foo mf0(2), mf1(2); | |
const Foo cf0(2), cf1(2); | |
printf("%i\n", (int)(mf0 >> 1)); // Emits "1" | |
printf("%i\n", (int)mf0); // Emits "1" | |
printf("%i\n", (int)(mf1 >>= 1)); // Emits "1" | |
printf("%i\n", (int)mf1); // Emits "1" | |
printf("%i\n", (int)(cf0 >> 1)); // Emits "1" | |
printf("%i\n", (int)cf0); // Emits "2" | |
printf("%i\n", (int)(cf1 >>= 1)); // Error | |
printf("%i\n", (int)cf1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment