Created
February 16, 2012 14:34
-
-
Save leviwilson/1845307 to your computer and use it in GitHub Desktop.
implicit C++ constructor conversions
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 <stdio.h> | |
class Foo { | |
public: | |
Foo(int blar) { | |
_member = blar; | |
} | |
operator int() const { | |
return _member; | |
} | |
private: | |
int _member; | |
}; | |
void PityTheFoo(Foo fooToBePitied) { | |
printf("I pity the foo of %d\n", (int)fooToBePitied); | |
} | |
int main(int argc, char* argv[]) { | |
Foo foo = 7; | |
printf("foo = %d\n", (int)foo); | |
PityTheFoo(11); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment