fork download
  1. #include <iostream>
  2. #include <mutex>
  3.  
  4. using namespace std;
  5.  
  6. std::once_flag flag;
  7.  
  8. class Class
  9. {
  10. public:
  11. Class()
  12. {
  13. std::call_once(flag, [this]{ SomeMethod(); });
  14. }
  15.  
  16. void SomeMethod()
  17. {
  18. cout << __func__ << endl;
  19. }
  20. };
  21.  
  22.  
  23. int main(int argc, const char * argv[])
  24. {
  25. Class x, y;
  26. x.SomeMethod();
  27. y.SomeMethod();
  28. }
  29.  
  30.  
  31.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
SomeMethod
SomeMethod
SomeMethod