fork download
  1. #include <iostream>
  2. using namespace std;
  3. int trw(int i)
  4. { cout<<endl<<"trwing int="<<i;
  5. throw (i);
  6. return i;
  7. }
  8. struct mm
  9. { ~mm(){cout<<endl<<"deleting mm="<<x;}
  10. explicit mm(int y ):x(y ){cout<<endl<<"constructing mm="<<x;}
  11. mm(const mm& m):x(m.x){cout<<endl<<"copying m.x=m."<<x;}
  12. mm& operator=(const mm& m){x=m.x; cout<<endl<<"assigning m."<<x; return *this;}
  13. mm& operator=(const int y){x=y; cout<<endl<<"assigning y" <<x; return *this;}
  14.  
  15. int x;
  16. };
  17. struct tr
  18. { mm a,b;
  19. tr():a(1),b(2) // tr() throw from constr body
  20. { cout<<endl<<"constructing tr()";
  21. trw(1);}
  22.  
  23. tr(int):a(3),b(trw(4)) {cout<<endl<<"constructing tr(int)";} // throw from constr init list
  24. tr(bool):a(5),b(6){cout<<endl<<"constructing tr(bool)";}
  25. ~tr(){cout<<endl<<"deleting tr: a="<<a.x<<" and b="<<b.x;}
  26. };
  27.  
  28. int main()
  29. {
  30. try{ tr d; }
  31. catch (int x){cout<<endl<<"int="<<x<<" ex. in tr()";}
  32.  
  33. try{ tr c(4); }
  34. catch (int x){cout<<endl<<"int="<<x<<" ex.in tr(int)";}
  35.  
  36. tr(true);
  37.  
  38. mm a(7);
  39. mm b=mm(8);
  40. mm c(a);
  41. b=c;
  42. mm e=9;
  43. return 0;
  44. }
Compilation error #stdin compilation error #stdout 0s 3032KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:42:10: error: conversion from ‘int’ to non-scalar type ‘mm’ requested
stdout
Standard output is empty