Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <functional>
  2. #include <string>
  3.  
  4. struct Foo {
  5. Foo(int) {}
  6. Foo(std::string) {}
  7. operator int () const { return 42; }
  8. operator std::string () const { return ""; }
  9.  
  10. void foo(std::function<void(Foo&, int)>f);
  11. void foo(std::function<void(const Foo&, int)>f) const; // xxx
  12.  
  13. void foo(std::function<void(const std::string&, Foo&)>f);
  14. void foo(std::function<void(const std::string&, const Foo&)>f) const;
  15.  
  16. void bar() const {
  17. this->foo([](const Foo&, int){}); // xxx
  18. }
  19. };
  20.  
  21. g++ -std=c++11 -c -Wall amb.cpp
  22. amb.cpp: In member function ‘void Foo::bar() const’:
  23. amb.cpp:18:40: error: call of overloaded ‘foo(Foo::bar() const::<lambda(const Foo&, int)>)’ is ambiguous
  24. this->foo([](const Foo&, int){});
  25. ^
  26. amb.cpp:12:10: note: candidate: void Foo::foo(std::function<void(const Foo&, int)>) const
  27. void foo(std::function<void(const Foo&, int)>f) const;
  28. ^
  29. amb.cpp:15:10: note: candidate: void Foo::foo(std::function<void(const std::basic_string<char>&, const Foo&)>) const
  30. void foo(std::function<void(const std::string&, const Foo&)>f) const;
  31. ^
  32.  
  33. #include <functional>
  34.  
  35. void foo(std::function<void(int)>f);
  36. void foo(std::function<void(double)>f);
  37.  
  38. void bar() {
  39. foo([](int){});
  40. }
  41.  
  42. amb2.cpp: In function ‘void bar()’:
  43. amb2.cpp:8:18: error: call of overloaded ‘foo(bar()::<lambda(int)>)’ is ambiguous
  44. foo([](int){});
  45. ^
  46. amb2.cpp:4:6: note: candidate: void foo(std::function<void(int)>)
  47. void foo(std::function<void(int)>f);
  48. ^
  49. amb2.cpp:5:6: note: candidate: void foo(std::function<void(double)>)
  50. void foo(std::function<void(double)>f);
  51. ^
  52.  
  53. this->foo(std::function<void(const Foo&, int)>([](const Foo&, int){}));
Add Comment
Please, Sign In to add comment