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