fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. struct clearable
  6. {
  7. void clear()
  8. {
  9. *((T*)this) = {};
  10. };
  11. };
  12.  
  13. class test : public clearable<test>
  14. {
  15. public:
  16. int a;
  17. };
  18.  
  19. int main()
  20. {
  21. test _test;
  22. _test.a=3;
  23. _test.clear();
  24.  
  25. printf("%d", _test.a);
  26.  
  27. return 0;
  28. }
  29.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'void clearable<T>::clear()':
prog.cpp:9:28: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
             *((T*)this) = {};
                            ^
prog.cpp: In function 'int main()':
prog.cpp:25:29: error: 'printf' was not declared in this scope
         printf("%d", _test.a);
                             ^
prog.cpp: In instantiation of 'void clearable<T>::clear() [with T = test]':
prog.cpp:23:21:   required from here
prog.cpp:9:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
             *((T*)this) = {};
                         ^
stdout
Standard output is empty