fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo
  5. {
  6. public:
  7. Foo() { }
  8. explicit Foo(const Foo&) { }
  9. Foo& operator = (const Foo& f) { return *this; }
  10. };
  11.  
  12. int main()
  13. {
  14. Foo a;
  15. Foo b(a); // OK, copy ctor
  16.  
  17. Foo c = a; // ERROR, copy ctor is explicit
  18.  
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 3292KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:17:10: error: no matching function for call to ‘Foo::Foo(Foo&)’
  Foo c = a; // ERROR, copy ctor is explicit
          ^
prog.cpp:17:10: note: candidate is:
prog.cpp:7:2: note: Foo::Foo()
  Foo() { }
  ^
prog.cpp:7:2: note:   candidate expects 0 arguments, 1 provided
stdout
Standard output is empty