fork download
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. void printListPointers(list<int> list);
  7. void printListPointers(list< list<int> > list);
  8.  
  9. class List {
  10. public:
  11. List(int, int);
  12. list< list<int> > root;
  13. };
  14.  
  15. List::List(int a, int b) {
  16. list<int> l;
  17. l.push_back(a);
  18. l.push_back(b);
  19. root.push_back(l);
  20. cout << "constructor: root "; printListPointers(root); cout << endl;
  21. cout << "constructor: first node in root "; printListPointers(*(root.begin())); cout << endl;
  22. }
  23.  
  24. int main() {
  25. List foo = List(2, 3);
  26. cout << "main: root "; printListPointers(foo.root); cout << endl;
  27. cout << "main: first node in root "; printListPointers(*(foo.root.begin())); cout << endl;
  28.  
  29. return 0;
  30. }
  31.  
  32. void printListPointers(list<int> l) {
  33. cout << "{";
  34. for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
  35. cout << &*it << ", ";
  36. }
  37. cout << "}" << endl;
  38. }
  39.  
  40. void printListPointers(list< list<int> > l) {
  41. cout << "{";
  42. for (list< list<int> >::iterator it = l.begin(); it != l.end(); it++) {
  43. cout << &*it << ", ";
  44. }
  45. cout << "}" << endl;
  46. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
constructor: root {0x8ce7068, }

constructor: first node in root {0x8ce7090, 0x8ce7080, }

main: root {0x8ce7068, }

main: first node in root {0x8ce7010, 0x8ce7020, }