fork download
  1. #include <iostream>
  2. using namespace std;
  3. class AnotherObjectType {};
  4.  
  5. class A {
  6. public:
  7. A(){count = 0;};
  8. int count;
  9. private:
  10. AnotherObjectType anotherObject;
  11. };
  12.  
  13. A f(){
  14. static A a;
  15. a.count++;
  16. //Other things...
  17. return a;
  18. }
  19.  
  20. int main() {
  21. // your code goes here
  22. A a;
  23. for (int i = 0; i < 3; i++) {
  24. a = f();
  25. std::cout << "Count: " << a.count << std::endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
Count: 1
Count: 2
Count: 3