Trouble Creating a Linked List of Objects

Hello, my assignment is to create a linked list of pointers to objects (in this case the 'video' class). I understand how to use linked lists for integers, but I'm kind of lost getting started with using objects.

Here's my .h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  4 class Vlist
  5 {
  6 public:
  7     Vlist ();
  8     ~Vlist ();
  9     void insert(Video::Video *video);
 10 private:
 11     class Node
 12     {
 13         public:
 14             Node (Video *video, Node *next)
 15             {m_value = &video; m_next = next;}
 16             int m_value;
 17             Node *m_next;
 18     };
 19     Node *m_head;
 20 };


What I want to be able to do is call
vlist.insert( new Video(...,...,...,...,...));

But I really don't know the syntax for doing it, and I'm not super comfortable with pointers and dereferencing and all that stuff.

If I can figure out how to get a working Node with the pointer in it, I can do the rest of the program no problem, but for now I'm stuck here. Thanks for any help you can give!

If you haven't figured this out yet, I hope you see this before the assignment is due!

Try creating the new videos inside your insert function, passing the arguments for your video object to the insert function. Do not pass the pointer to your video object to the insert function, instead make the pointer to the video a member variable of your Node class:

Video *m_video;

When you are trying to access your video in main() for say, a print function, then you can do this, assuming your video object has a member function for printing:

ptr->m_video->print();

Hope this helps :D!
Topic archived. No new replies allowed.