Created
September 10, 2011 00:11
-
-
Save timmaxw/1207668 to your computer and use it in GitHub Desktop.
C++ puzzle
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 <iostream> | |
/* Under GCC 4.4.1, VERSION_1 fails but VERSION_2 and VERSION_3 work. */ | |
#ifdef VERSION_1 | |
void show(std::string s) { | |
std::cout << s << std::endl; | |
} | |
template<class T> | |
void do_show(T t) { | |
show(t); | |
} | |
void show(int i) { | |
std::cout << i << std::endl; | |
} | |
int main(void) { | |
do_show(2); | |
return 0; | |
} | |
#endif | |
#ifdef VERSION_2 | |
void show(std::string s) { | |
std::cout << s << std::endl; | |
} | |
void show(int i) { | |
std::cout << i << std::endl; | |
} | |
template<class T> | |
void do_show(T t) { | |
show(t); | |
} | |
int main(void) { | |
do_show(2); | |
return 0; | |
} | |
#endif | |
#ifdef VERSION_3 | |
template<class T> | |
void do_show(T t) { | |
show(t); | |
} | |
void show(std::string s) { | |
std::cout << s << std::endl; | |
} | |
void show(int i) { | |
std::cout << i << std::endl; | |
} | |
int main(void) { | |
do_show(2); | |
return 0; | |
} | |
#endif |
After I posted this Gist I made a question on Stack Overflow; this excellent answer made everything clear for me. I think you're right that only VERSION_2
is valid.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only VERSION_2 is valid as per 14.6.3/1 and 14.6/9.