Guest User

Untitled

a guest
Nov 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. struct X {};
  2.  
  3. template<typename T>
  4. int foo(T n) {
  5. return n;
  6. }
  7.  
  8. template<>
  9. int foo<const X&>(const X& n) {
  10. return -1;
  11. }
  12.  
  13. int main() {
  14. const X x;
  15. const X& rx = x;
  16.  
  17. int n1 = foo(0); // OK
  18. int n2 = foo(rx); // ERROR:
  19. // In instantiation of 'int foo(T) [with T = X]':
  20. //error: cannot convert 'X' to 'int' in return
  21.  
  22. return 0;
  23. }
  24.  
  25. template<typename T>
  26. int foo(T n) {
  27. return n;
  28. }
  29.  
  30. template<typename T>
  31. int foo(T n) {
  32. return n;
  33. }
  34.  
  35. int foo(const X& n) {
  36. return -1;
  37. }
Add Comment
Please, Sign In to add comment