943,846 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5412
  • C++ RSS
Nov 20th, 2008
0

Linked List of struct

Expand Post »
I am creating a linked list which links a struct of data together. However, this is my problem, if I declare struct Node first then the Event type wont exist, but if I declare struct Event first then nodePtr wont exist....im kinda stuck here as to how I should declare them.

C++ Syntax (Toggle Plain Text)
  1. struct Event
  2. {
  3. void addEvent();
  4.  
  5. tm startTime, endTime;
  6. string eventItem;
  7. string eventNotes;
  8. char allDay;
  9. nodePtr head, tail;
  10.  
  11. };
  12.  
  13.  
  14. struct Node
  15. {
  16. Event eventNode;
  17. Node *next;
  18. };
  19.  
  20. typedef Node* nodePtr;
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
number87 is offline Offline
83 posts
since Jan 2008
Nov 20th, 2008
0

Re: Linked List of struct

Not sure of what you want to accomplish here. This piece of info might help getting the same results using a different method.
Reputation Points: 10
Solved Threads: 4
Light Poster
emotionalone is offline Offline
33 posts
since Oct 2008
Nov 20th, 2008
0

Re: Linked List of struct

ok what im trying to do have a list of Events (which are actually a struct type containning data such as time date etc). And my problem as can be seen above is that I do not know how to resolve their declarations. I cant declare struct Event first because it contains pointers to the next Event struct. And I cant declare struct Node first because the node is of Event type.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
number87 is offline Offline
83 posts
since Jan 2008
Nov 21st, 2008
0

Re: Linked List of struct

c++ Syntax (Toggle Plain Text)
  1. struct Event
  2. {
  3. void addEvent();
  4.  
  5. tm startTime, endTime;
  6. string eventItem;
  7. string eventNotes;
  8. char allDay;
  9. nodePtr *head, *tail; //-- a pointer!, maybe...
  10.  
  11. };
  12.  
  13.  
  14. struct Node
  15. {
  16. Event *eventNode; //-- a pointer!, maybe.
  17. Node *next;
  18. };
  19.  
  20. typedef Node* nodePtr;
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 21st, 2008
0

Re: Linked List of struct

Maybe, you confused the functionality of Event struct and Node struct.

There are two ways to reach you objective.
First,
C++ Syntax (Toggle Plain Text)
  1. struct EventNode
  2. {
  3. tm startTime, endTime;
  4. string eventItem;
  5. string eventNotes;
  6. char allDay;
  7.  
  8. EventNode* next;
  9. };
  10.  
  11. struct EventList
  12. {
  13. void addEvent();
  14. ... // other member functions used to sustain the list
  15. private:
  16. EventNode* head;
  17. EventNode* tail;
  18. };

another way use the list of STL to store the event.

C++ Syntax (Toggle Plain Text)
  1. struct Event
  2. {
  3. tm startTime, endTime;
  4. string eventItem;
  5. string eventNotes;
  6. char allDay;
  7. };
  8.  
  9. std::list<Event> eventList;
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Nov 21st, 2008
0

Re: Linked List of struct

ah ok i get what u mean
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
number87 is offline Offline
83 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Homework Function Compile Errors
Next Thread in C++ Forum Timeline: flashing characters (without clearing the screen)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC