Linked List of forms

This is a discussion on Linked List of forms within the C++ Programming forums, part of the General Programming Boards category; I want to create a linked list of forms. I am using this code to create the form Code: ChildForm ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    37

    Linked List of forms

    I want to create a linked list of forms. I am using this code to create the form

    Code:
    ChildForm = new TChildForm(this);
    For the linked list I know I need a structure:

    Pointer to Childform
    Pointer to next node

    I need to know which part do I assign to the pointer to childform.

    Thanks

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I need to know which part do I assign to the pointer to childform.
    Unless this is a school assignment where you have to roll your own list, it's easier and faster and safer to use C++'s list class
    Code:
    #include <list>
    
    using namespace std;
    
    int main()
    {
      list<TChildForm *> myList;
    }
    Then you can treat it like a vector that's safe to insert anywhere. :-) If you have to roll your own then this is a good start
    Code:
    struct node {
      explicit node(TChildForm *content, node *link): form(content), next(link)
      {}
    
      TChildForm *form;
      node *next;
    };
    
    int main()
    {
      node *head = 0;
    
      for (int i = 0; i < 10; i++) // Or some kind of loop
      {
        node *np = new node(new TChildForm(), head);
        head = np;
      }
    
      // Work with the list then free it
    }
    *Cela*

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    37
    In an MDI application in Borland C++ Builder.
    If the list is declared in the Parent form globally is it visible in each of the child forms.

    I know global variables is bad programming practice

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-04-2006, 05:39 PM
  2. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 08:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21