fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template<typename DATA_TYPE>
  5. void Push(const typename std::remove_pointer<DATA_TYPE>::type& newValue)
  6. {
  7. std::cout<<"Const & version"<<std::endl;
  8. }
  9.  
  10. template<typename DATA_TYPE>
  11. void Push(const DATA_TYPE *newValue)
  12. {
  13. std::cout<<"Const * version"<<std::endl;
  14. }
  15.  
  16. int main()
  17. {
  18. int i=7;
  19. Push(i);
  20. Push(&i);
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:11: error: no matching function for call to ‘Push(int&)’
prog.cpp:19:11: note: candidates are:
prog.cpp:5:6: note: template<class DATA_TYPE> void Push(const typename std::remove_pointer<DATA_TYPE>::type&)
prog.cpp:5:6: note:   template argument deduction/substitution failed:
prog.cpp:19:11: note:   couldn't deduce template parameter ‘DATA_TYPE’
prog.cpp:11:6: note: template<class DATA_TYPE> void Push(const DATA_TYPE*)
prog.cpp:11:6: note:   template argument deduction/substitution failed:
prog.cpp:19:11: note:   mismatched types ‘const DATA_TYPE*’ and ‘int’
stdout
Standard output is empty