fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. inline int get_int(T const& in)
  5. {
  6. std::cout << "In get_int!\n";
  7. return in;
  8. }
  9.  
  10. inline int get_int(char const& in)
  11. {
  12. std::cout << "In get_int(char)!\n";
  13. return static_cast<int>(in);
  14. }
  15.  
  16. inline unsigned int get_int(unsigned char const& in)
  17. {
  18. std::cout << "In get_int(unsigned char)!\n";
  19. return static_cast<unsigned int>(in);
  20. }
  21.  
  22. template<typename T>
  23. void go(T const& arg)
  24. {
  25. auto result = get_int(arg);
  26. std::cout << "The integer is " << result << "\n";
  27. }
  28.  
  29. int main()
  30. {
  31. go(static_cast<unsigned char>('a'));
  32. go('a');
  33. go(42);
  34. }
  35.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
In get_int(unsigned char)!
The integer is 97
In get_int(char)!
The integer is 97
In get_int!
The integer is 42