Thread: Link list of objects

  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
    28,413
    You could use #include <list> and use std::list, which is a doubly linked list class template.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,318
    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, 09: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, 10:21 PM