Link list of objects

This is a discussion on Link list of objects within the C++ Programming forums, part of the General Programming Boards category; How would one go about making a link list of objects assuming i already have the class made?...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    Link list of objects

    How would one go about making a link list of objects assuming i already have the class made?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,275
    You could use #include <list> and use std::list, which is a doubly linked list class template.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You already made the class, correct? Where are you stuck exactly?

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    16
    well, i wrote a previous program where i used a linked list of structs to represent a polynomial broken up into its coeffficients and powers and then passed the pointer to the first structs to various functions to do operations. Now i need the same thing but using objects. I want to create an object with a coefficient and power which is linked to another object that has a coefficient and power and so on until it reaches a null character but i'm not sure, once i create the first object with a constructer, how to link the next one to it

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well as the kindly laserlight pointed out the stl provides you with a generic template class for *drum roll* linked lists. Just use that.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Yeah you'll need to better show us what you are having trouble with, in other words, code.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Code:
    std::list<YourClassNameGoesHere> listVar;
    YourClassNameGoesHere obj;
    listVar.push_back( obj );
    ...
    More info about STL Lists: http://www.cppreference.com/cpplist/index.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading data from a file - link list
    By peter_hii in forum C++ Programming
    Replies: 7
    Last Post: 10-25-2006, 10:11 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  4. 1st Class LIST ADT
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-09-2001, 07:29 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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