fork download
  1. #include <type_traits>
  2. #include <stdlib.h>
  3. #include <iostream>
  4.  
  5. template <class T, class = >
  6. void fun(T, typename std::enable_if<std::is_fundamental<T>::value>::type)
  7. {
  8. printf("hi");
  9. }
  10.  
  11. template <class T>
  12. void fun(T)
  13. {
  14. std::cout << "sup";
  15. }
  16.  
  17. int main()
  18. {
  19. fun(5);
  20. }
Compilation error #stdin compilation error #stdout 0s 2892KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.7/type_traits:35:0,
                 from prog.cpp:1:
/usr/include/c++/4.7/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
prog.cpp:5:28: error: expected type-specifier before ‘>’ token
prog.cpp:6:27: error: ‘enable_if’ in namespace ‘std’ does not name a type
prog.cpp:6:36: error: expected ‘,’ or ‘...’ before ‘<’ token
prog.cpp:6:73: error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11
prog.cpp: In function ‘void fun(T, int)’:
prog.cpp:8:16: error: there are no arguments to ‘printf’ that depend on a template parameter, so a declaration of ‘printf’ must be available [-fpermissive]
prog.cpp:8:16: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
stdout
Standard output is empty