fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Foo {
  5. Foo() { cout << "default\n"; }
  6. Foo(const long long) { cout << "implicit\n"; }
  7. };
  8.  
  9. struct Bar {
  10. Bar(const short param) : param(param) {}
  11. operator long long() const { return static_cast<long long>(param); }
  12. const short param;
  13. };
  14.  
  15. int main() {
  16. Foo foo = Bar(13);
  17. }
Compilation error #stdin compilation error #stdout 0s 4348KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:13: error: conversion from ‘Bar’ to non-scalar type ‘Foo’ requested
   Foo foo = Bar(13);
             ^~~~~~~
stdout
Standard output is empty