fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct vertex;
  7.  
  8. vector< vertex > t;
  9.  
  10. struct vertex {
  11. int nxt;
  12. vertex() {
  13. nxt = 0;
  14. }
  15. int getNext() {
  16. if( nxt == 0 ) {
  17. cout << "t.size() = " << t.size() << endl;
  18. nxt = t.size();
  19. cout << "new nxt = " << nxt << endl;
  20. t.push_back( vertex() );
  21. }
  22. cout << "nxt = " << nxt << endl;
  23. return nxt;
  24. }
  25. };
  26.  
  27. int main() {
  28. t.push_back( vertex() );
  29. cout << t[0].getNext() << endl;
  30. cout << t[0].getNext() << endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
t.size() = 1
new nxt = 1
nxt = 0
0
nxt = 1
1