fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. struct clearable
  6. {
  7. void clear()
  8. {
  9. static T _clear;
  10. *((T*)this) = _clear;
  11. };
  12. };
  13.  
  14. class test : public clearable<test>
  15. {
  16. public:
  17. int a;
  18. };
  19.  
  20. int main()
  21. {
  22. test _test;
  23. _test.a=3;
  24. _test.clear();
  25.  
  26. printf("%d", _test.a);
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty