fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class BookID
  5. {
  6. int id;
  7. public:
  8. explicit BookID(int id = 0) : id(id) {}
  9. explicit operator int() const { return id; }
  10. };
  11.  
  12. class CustomerID
  13. {
  14. int id;
  15. public:
  16. explicit CustomerID(int id = 0) : id(id) {}
  17. explicit operator int() const { return id; }
  18. };
  19.  
  20. int main()
  21. {
  22. BookID bookId;
  23. CustomerID custId;
  24.  
  25. bookId = custId; // <-- fails!
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:25:11: error: no match for ‘operator=’ (operand types are ‘BookID’ and ‘CustomerID’)
  bookId = custId; // <-- fails!
           ^~~~~~
prog.cpp:4:7: note: candidate: ‘constexpr BookID& BookID::operator=(const BookID&)’
 class BookID
       ^~~~~~
prog.cpp:4:7: note:   no known conversion for argument 1 from ‘CustomerID’ to ‘const BookID&’
prog.cpp:4:7: note: candidate: ‘constexpr BookID& BookID::operator=(BookID&&)’
prog.cpp:4:7: note:   no known conversion for argument 1 from ‘CustomerID’ to ‘BookID&&’
stdout
Standard output is empty