Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Created February 16, 2012 14:34
Show Gist options
  • Save leviwilson/1845307 to your computer and use it in GitHub Desktop.
Save leviwilson/1845307 to your computer and use it in GitHub Desktop.
implicit C++ constructor conversions
#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