fork download
  1. #include <cstdlib>
  2.  
  3. struct S {
  4. void *operator new(std::size_t) {
  5. i = 10;
  6. return nullptr;
  7. }
  8.  
  9. int i;
  10. };
  11.  
  12.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void* S::operator new(std::size_t)’:
prog.cpp:9:9: error: invalid use of member ‘S::i’ in static member function
     int i;
         ^
prog.cpp:5:9: error: from this location
         i = 10;
         ^
prog.cpp:6:16: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect) [enabled by default]
         return nullptr;
                ^
stdout
Standard output is empty