fork(1) download
  1. include <iostream>
  2. include <cstdint>
  3.  
  4. union P {
  5. timeval _timeval;
  6. int8_t _int8_t;
  7. uint8_t _uint8_t;
  8.  
  9. operator const timeval() const {
  10. return _timeval;
  11. }
  12.  
  13. operator const int8_t() const {
  14. return _int8_t;
  15. }
  16. };
  17.  
  18.  
  19. struct Y {
  20.  
  21. operator const int8_t() const {
  22. return static_cast<int8_t>(_p);
  23. }
  24.  
  25. operator const timeval() const {
  26. return static_cast<timeval>(_p);
  27. }
  28.  
  29. P _p;
  30. };
  31.  
  32. int main()
  33. {
  34.  
  35. Y testobj();
  36. timeval ret = static_cast<timeval>(testobj);
  37. return 0;
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘include’ does not name a type
 include <iostream>
 ^
prog.cpp:21:20: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
     operator const int8_t() const {
                    ^
prog.cpp:21:5: error: ‘operator const int’ does not name a type
     operator const int8_t() const {
     ^
prog.cpp:25:20: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
     operator const timeval() const {
                    ^
prog.cpp:25:5: error: ‘operator const int’ does not name a type
     operator const timeval() const {
     ^
prog.cpp:29:5: error: ‘P’ does not name a type
     P _p;
     ^
prog.cpp: In function ‘int main()’:
prog.cpp:36:5: error: ‘timeval’ was not declared in this scope
     timeval ret = static_cast<timeval>(testobj);
     ^
prog.cpp:36:13: error: expected ‘;’ before ‘ret’
     timeval ret = static_cast<timeval>(testobj);
             ^
stdout
Standard output is empty