Last active
December 16, 2015 06:49
-
-
Save phire/5394592 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 <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