fork download
  1. #include <vector>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int nextid = 0;
  8. class Entry {
  9. public:
  10. string data;
  11. int myid;
  12. Entry(string in) {
  13. data = in;
  14. myid = nextid;
  15. nextid++;
  16. printf("Entry%02d\n", myid);
  17. }
  18. ~Entry() { printf("~Entry%02d\n", myid); }
  19. };
  20.  
  21. class Meep {
  22. public:
  23. vector<Entry> stuff;
  24. };
  25.  
  26. void think(Meep m) {
  27. m.stuff.push_back(Entry(string("fluttershy")));
  28. }
  29.  
  30. int main() {
  31.  
  32. Meep a;
  33. a.stuff.push_back(Entry(string("applejack")));
  34. think(a);
  35. vector<Entry>::iterator it;
  36. int i = 0;
  37. for (it=a.stuff.begin(); it!=a.stuff.end(); it++) {
  38. printf("a.stuff[%d] = %s\n", i, (*it).data.c_str());
  39. i++;
  40. }
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46.  
  47.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
Entry00
~Entry00
Entry01
~Entry00
~Entry01
~Entry00
~Entry01
a.stuff[0] = applejack
~Entry00