Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. template <class T1> class foo {
  4. public:
  5.     template <class T2> static void bar();
  6. };
  7.  
  8. template <class T1>
  9. template <class T2>
  10. void foo<T1>::bar() {
  11.     printf("Hello World GENERIC\n");
  12. }
  13.  
  14. template<>
  15. template<>
  16. void foo<int>::bar<float>() {
  17.     printf("Hello World IF\n");
  18. }
  19.  
  20. template<>
  21. template<>
  22. void foo<float>::bar<int>() {
  23.     printf("Hello World FI\n");
  24. }
  25.  
  26. int main() {
  27.     // prints Hello World IF
  28.     foo<int>::bar<float>();
  29.     // prints Hello World Generic
  30.     foo<float>::bar<float>();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement