Thread: Linking issue.

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    1

    Linking issue.

    I'm currently completely an assignment for my software engineering course at university and I've run into a brick wall when trying to put everything together.

    The assignment consists of a Linked List class, Node class and a Train class. I've finished implementing the Node / Linked List classes but when trying to compile a TrainDemo I keep getting this linking error:

    /tmp/ccmZn5Ek.o:Train.cpp:<.text+0x2e>: undefined reference to 'linked_list_class::linkedlist::list_locate<node_c lass_trent::node*, unsigned int>'

    Here's the .h for my Train class:

    Code:
    #ifndef TRAIN_MACRO_GUARD#define TRAIN_MACRO_GUARD
    #include "linkedlist.h"
    
    
    using namespace linked_list_class; 
    
    
    namespace train_class
    {
        class Train
        {
            public:
                    typedef node::value_type value_type;
                    
                    // Constructors;
                    Train();
                    Train(int arr[]);
                    
                    // Destructors;
                    ~Train();
                    
                    // Mutating member functions;
                    void addLoad(int i, int j); // i = Kilograms of coal, j = Carridge;
                    void removeLoad(int i, int j); // i = Kilograms of coal, j = Carridge;
                    void removeCar(int i);
                    void cleanTrain();
                    
                    // Non-mutating member functions;
                    int totalLoad();
                    int size();
            
            private:
                    linkedlist* list;
        };
    }
    
    
    #endif
    Here's what I've written for the .cpp of the Train class so far:

    Code:
    #include "Train.h"
    
    namespace train_class
    {
        // Constructors;
        Train::Train()
        {
             list = new linkedlist();
        }
        
        Train::Train(int arr[])
        {
            list = new linkedlist();
            
            for(int i = 0; i != -1; i++) // Minus -1 workaround to find the end of the array due to sizeof() issues;
              {
                list->list_head_insert(list->get_head(),i);
            }
        }
        
        // Mutating member functions;
        void Train::addLoad(int i, int j)
        {
            node* new_node;
            new_node = list->list_locate(list->get_head(),j++); // list_locate returns a pointer to the previous node instead of the one we're looking for;
            new_node->set_data(i);                               // This isn't a bad thing as some functions ( such as list_insert ) need the previous pointer;
        }                                                         // As a workaround to avoid implementing a variation of the list_locate function to return
    }                                                            // the actual node we're looking for, we can just add +1 to j;
    And here's the .cpp I was using to test the Train class:

    Code:
    #include "Train.h"
    
    using namespace std;
    using namespace train_class;
    
    
    int main(void)
    {
        Train* new_train = new Train();
    }
    Any help would be fantastic.

    Thank you.
    Last edited by urthwrm; 09-20-2011 at 09:58 AM.

  2. #2
    Registered User
    Join Date
    Aug 2011
    Location
    Montreal, Quebec, Canada
    Posts
    73
    You did not include your linked list header in train.cpp.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem is with the linkedlist class. Have you included the file in your project / compiled the files for the class?
    If so, and the problem remains, post the contents for that class.

    Also, you realize there is no need to allocate a new linked list on the heap, right? Also, your destructor is missing.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. MinGW linking issue
    By ascen in forum Windows Programming
    Replies: 1
    Last Post: 03-31-2010, 04:26 AM
  3. gcc - linking to cwd
    By mike_g in forum Tech Board
    Replies: 3
    Last Post: 08-15-2008, 03:38 PM
  4. Linking MFC dll to .NET app
    By Raptor in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2005, 08:49 AM
  5. ld: linking
    By ilear_01 in forum C++ Programming
    Replies: 0
    Last Post: 06-10-2003, 05:40 AM