fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename T>
  5. struct Point
  6. {
  7. template<typename U = T>
  8. typename std::enable_if<std::is_same<U, int>::value>::type
  9. MyFunction()
  10. {
  11. std::cout << "T is int." << std::endl;
  12. }
  13.  
  14. template<typename U = T>
  15. typename std::enable_if<std::is_same<U, float>::value>::type
  16. MyFunction()
  17. {
  18. std::cout << "T is not int." << std::endl;
  19. }
  20. };
  21.  
  22. int main()
  23. {
  24. Point<int> intPoint;
  25. intPoint.MyFunction();
  26.  
  27. Point<float> floatPoint;
  28. floatPoint.MyFunction();
  29. }
  30.  
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
T is int.
T is not int.