fork download
  1. #include <iostream>
  2.  
  3. class Test
  4. {
  5. public:
  6. Test(int _data, Test *_next = nullptr):data(_data), next(_next)
  7. {}
  8. int data;
  9. Test *next;
  10. };
  11.  
  12. int main()
  13. {
  14. Test test_node1(1);
  15. Test test_node2(2);
  16. Test test_node3(3);
  17.  
  18. test_node1.next = &test_node2;
  19. test_node2.next = &test_node3;
  20.  
  21. for (Test *curr_node = &test_node1; curr_node != nullptr; curr_node = curr_node->next)
  22. {
  23. std::cout<<"Data: " <<curr_node->data<<std::endl;
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Data: 1
Data: 2
Data: 3