fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <class Derived>
  5. struct Base
  6. {
  7. Base()
  8. {
  9. static_cast<Derived*>(this)->foo();
  10. }
  11.  
  12. std::vector<int> m_ints;
  13. };
  14.  
  15. struct Derived : Base<Derived>
  16. {
  17. Derived() : Base()
  18. {
  19. std::cout << a;
  20. }
  21.  
  22. void foo()
  23. {
  24. m_ints.push_back(37);
  25. a = 4;
  26. }
  27.  
  28. int a;
  29. };
  30.  
  31. int main()
  32. {
  33. Derived d;
  34. return 0;
  35. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
4