fork download
  1. #include <iostream>
  2.  
  3. struct A { };
  4.  
  5. struct B {
  6. B(){}
  7. explicit B(const A& a) {
  8. std::cout << "constructor" << std::endl;
  9. }
  10.  
  11. //B& operator=(const A& a) {
  12. // cout << "assignment operator" << endl;
  13. // return *this;
  14. //}
  15. };
  16.  
  17. int main() {
  18. A a;
  19. B b;
  20. b = a;
  21.  
  22. return 0;
  23. }
  24.  
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:20:7: error: no match for 'operator=' (operand types are 'B' and 'A')
     b = a;
       ^
prog.cpp:5:8: note: candidate: B& B::operator=(const B&)
 struct B {
        ^
prog.cpp:5:8: note:   no known conversion for argument 1 from 'A' to 'const B&'
prog.cpp:5:8: note: candidate: B& B::operator=(B&&)
prog.cpp:5:8: note:   no known conversion for argument 1 from 'A' to 'B&&'
stdout
Standard output is empty