fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct Nathan {
  5. long getHash(){return 0;}
  6. };
  7.  
  8. template <typename T>
  9. void func(T value)
  10. {
  11. if (std::is_pointer<T>::value)
  12. std::cout << value->getHash();
  13. else
  14. std::cout << value.getHash();
  15. }
  16.  
  17. int main()
  18. {
  19. Nathan n;
  20. func(n);
  21. func(&n);
  22. }
  23.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void func(T) [with T = Nathan]’:
prog.cpp:20:11:   required from here
prog.cpp:12:9: error: base operand of ‘->’ has non-pointer type ‘Nathan’
prog.cpp: In instantiation of ‘void func(T) [with T = Nathan*]’:
prog.cpp:21:12:   required from here
prog.cpp:14:9: error: request for member ‘getHash’ in ‘value’, which is of pointer type ‘Nathan*’ (maybe you meant to use ‘->’ ?)
stdout
Standard output is empty