Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. template<typename T> return_type fun_name();
  2. template<> return_type fun_name<int>(){/* blabla */}
  3.  
  4. //-------------failed case-------------
  5. template <typename T>
  6. struct deduce{
  7. typedef T* type;
  8. };
  9.  
  10.  
  11. template <typename T>
  12. typename deduce<T>::type fun1();
  13.  
  14. template <>
  15. typename deduce<float>::type fun1<float>() //error if no "<float>" after fun1
  16. {
  17.  
  18. }
  19.  
  20. //------------now the "Template Argument Deduction" works------------
  21. template <typename T>
  22. struct some_struct{
  23. T* p;
  24. };
  25.  
  26. template <typename T>
  27. some_struct<T> fun2();
  28.  
  29. template <>
  30. some_struct<float> fun2() // no error even if no "<float>" after fun2
  31. {
  32.  
  33. }
  34.  
  35. error: template-id β€˜fun1<>’ for β€˜float* fun1()’ does not match any template declaration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement