fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Widget {
  5. Widget(int) { cout << "ctor" << endl; }
  6. Widget(const int&) { cout << "ctor" << endl; }
  7. };
  8.  
  9. struct Gadget {
  10. Gadget(const int&) { cout << "ctor" << endl; }
  11. Gadget(int&&) { cout << "ctor" << endl; }
  12. };
  13.  
  14. int main() {
  15. int x = 5;
  16. Widget{x};
  17. Widget{10};
  18. Gadget{x};
  19. Gadget{10};
  20. return 0;
  21. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:16:10: error: call of overloaded 'Widget(<brace-enclosed initializer list>)' is ambiguous
  Widget{x};
          ^
prog.cpp:6:2: note: candidate: Widget::Widget(const int&)
  Widget(const int&) { cout << "ctor" << endl; }
  ^
prog.cpp:5:2: note: candidate: Widget::Widget(int)
  Widget(int) { cout << "ctor" << endl; }
  ^
prog.cpp:4:8: note: candidate: constexpr Widget::Widget(const Widget&)
 struct Widget {
        ^
prog.cpp:4:8: note: candidate: constexpr Widget::Widget(Widget&&)
prog.cpp:17:11: error: call of overloaded 'Widget(<brace-enclosed initializer list>)' is ambiguous
  Widget{10};
           ^
prog.cpp:6:2: note: candidate: Widget::Widget(const int&)
  Widget(const int&) { cout << "ctor" << endl; }
  ^
prog.cpp:5:2: note: candidate: Widget::Widget(int)
  Widget(int) { cout << "ctor" << endl; }
  ^
prog.cpp:4:8: note: candidate: constexpr Widget::Widget(const Widget&)
 struct Widget {
        ^
prog.cpp:4:8: note: candidate: constexpr Widget::Widget(Widget&&)
stdout
Standard output is empty