Skip to content

Instantly share code, notes, and snippets.

@phire
Last active December 16, 2015 06:49
Show Gist options
  • Save phire/5394592 to your computer and use it in GitHub Desktop.
Save phire/5394592 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef union mytype {
const char *string;
int num;
mytype(int n) : num(n) {}
mytype(const char *n) : string(n) {}
} mytype;
template<int pass>
mytype test() {
if(pass == 1) {
mytype a = {"string"};
return a;
} else {
mytype b = {1};
return b;
}
}
int main(int argc, char **argv) {
printf("%s\n", test<1>().string);
printf("%i\n", test<0>().num);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment