Thread: how to use this linked list?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    how to use this linked list?

    can someone tell me how to create an instance of this linked list and add a member to it?

    Code:
    template<class T>
    class LinkedList : public BaseRefCollection<T> {
    public:
        typedef T MemberType;
        LinkedList() : version_(0),members_(0),head_(0),tail_(0) {}
        LinkedList( LinkedList<T> * ll ) : head_(ll->head()) {}
    
        const T * head() const { return head_.ptr(); }
        T * head() { return head_.ptr(); }
        void newMember( T * _newMember ) {
          if( tail_ ) {
             tail_->llNextIs(_newMember);
          }
          else head_ = _newMember;
          _newMember->llNextIs(0);
          tail_ = _newMember;
          ++version_;
          ++members_;
        }
        void newMember( const typename T::Ptr& _newMember ) {
           newMember(_newMember.ptr() );
        }
    
        .
        .
        .
    
    }
    this line works:
    LinkedList<myType> linkedList();

    do i need to allocate memory for it before i can add a member, and how do i add a member?

    Thanks!

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    This isn't C, and the code is messy. Looks like you just hand it a pointer to whatever paramaterized type you gave the list. In your case a * myType to the newMember method.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Is there a reason you aren't using the standard std::list in the <list> header?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Perhaps finding a C example may be clearer to you. I think you are having trouble since this is a C++ class. If you are learning C. A C++ class will just look quite confusing.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Perhaps the poor soul is actually doing C and found some C++ code and was wondering WTF is this and how do I use it?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I think that is probably the case. They may be similar languages, but any template will baffle someone not acquainted with C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM