Advertisement
Guest User

Untitled

a guest
Jul 8th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. [jwalden@find-waldo-now tmp]$ cat amb.cpp
  2. #include <iostream>
  3.  
  4. template<typename derived_t>
  5. struct protocol_object {};
  6.  
  7. struct data_object : public protocol_object<data_object> {};
  8.  
  9. struct conversion_required { conversion_required(int) {} };
  10.  
  11. template<typename derived_t>
  12. void match_impl(protocol_object<derived_t> &value, int)
  13. {
  14.    std::cout << "protocol_class";
  15. };
  16.  
  17. template<typename T>
  18. void match_impl(T &value, conversion_required)
  19. {
  20.    std::cout << "any other type";
  21. };
  22.  
  23. template<typename T>
  24. void match(T& value)
  25. {
  26.     return match_impl(value, 0);
  27. }
  28.  
  29. int main()
  30. {
  31.   data_object d;
  32.   int i;
  33.   match(d);
  34.   match(i);
  35. }
  36. [jwalden@find-waldo-now tmp]$ g++48 -oamb amb.cpp
  37. amb.cpp: In instantiation of β€˜void match(T&) [with T = data_object]’:
  38. amb.cpp:32:10:   required from here
  39. amb.cpp:25:31: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [enabled by default]
  40.      return match_impl(value, 0);
  41.                                ^
  42. amb.cpp:11:6: note: candidate 1: void match_impl(protocol_object<derived_t>&, int) [with derived_t = data_object]
  43.  void match_impl(protocol_object<derived_t> &value, int)
  44.       ^
  45. amb.cpp:17:6: note: candidate 2: void match_impl(T&, conversion_required) [with T = data_object]
  46.  void match_impl(T &value, conversion_required)
  47.       ^
  48. [jwalden@find-waldo-now tmp]$ clang++-tip -oamb amb.cpp
  49. amb.cpp:25:12: error: call to 'match_impl' is ambiguous
  50.     return match_impl(value, 0);
  51.            ^~~~~~~~~~
  52. amb.cpp:32:3: note: in instantiation of function template specialization 'match<data_object>' requested here
  53.   match(d);
  54.   ^
  55. amb.cpp:11:6: note: candidate function [with derived_t = data_object]
  56. void match_impl(protocol_object<derived_t> &value, int)
  57.      ^
  58. amb.cpp:17:6: note: candidate function [with T = data_object]
  59. void match_impl(T &value, conversion_required)
  60.      ^
  61. 1 error generated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement