Thread: passing linked lists as references !!

  1. #1
    Unregistered
    Guest

    Angry passing linked lists as references !!

    Does anyone know how to pass a linked list (of objects) as a reference ??

    I can get my program working if I have the list global but I assume this is bad coding ??

    Thanx

    Lisa
    x

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    just pass the address of the head node. remember that from that node to can walk to anywhere within the list by following the next pointers. You could also pass as a reference to the head object of the list etc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Unregistered
    Guest

    still cant do!!

    OK, I still can't get it working, here is an example of what I am doing:

    I have a linked list of videos (called li):

    list <vid> li;

    I have declared an iterator (not sure if it helps)

    list<vid>::iterator it;

    I want to print out the list of films in a seperate function to main, I therefore need to pass a reference to the list into the function !!??

    I need some sample code to help me please, this is really bugging me now !!!

    Thanks

    L

  4. #4
    Unregistered
    Guest

    Talking Solved it !!

    OK, solved it myself by passing the list as a reference , seemed to work:


    in main :

    viewList(li);


    Function prototype :

    void viewList(list<vid> &li);

    can then use li as normal.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 05:30 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM