Member Avatar for jtbens01

Hey guys, I'm getting some kind of linker error. Any help would be appreciated.

Here is what I have..

Header File:

           #ifndef _LinkedSortedList_
            #define _LinkedSortedList_

            #include "LinkedNode.h"
            #include "SortedList.h"

            template <class Elm> 
            class LinkedSortedList : public SortedList<Elm>
            {
            public:

                LinkedSortedList();
                ~LinkedSortedList();
                void clear();
                bool insert(Elm newValue);
                bool getfirst(Elm &returnValue);
                void print() const;
                bool find(Elm searchValue) const;
                int size() const;

            private:

                LinkedNode<Elm>* head;

            };
            #endif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
.cpp
#include <iostream>
#include "LinkedSortedList.h"
#include "LinkedNode.h"

            using namespace std;

            template<class Elm>
            LinkedSortedList<Elm>::LinkedSortedList()
            {
                head = NULL;
            }

            template<class Elm>
            LinkedSortedList<Elm>::~LinkedSortedList()
            {
                clear();
                head = NULL;
            }

            template<class Elm>
            void LinkedSortedList<Elm>::clear()
            {
                LinkedNode<Elm>* remove;

                while (head != NULL)
                {
                    remove = head;
                    head = head->next;
                    delete remove;
                }
            }

            template<class Elm>
            bool LinkedSortedList<Elm>::find(Elm searchValue) const
            {
                return false;
            }

            template<class Elm>
            bool LinkedSortedList<Elm>::getfirst(Elm &returnValue)
            {
                return false;
            }

            template<class Elm>
            bool LinkedSortedList<Elm>::insert(Elm newValue)
            {
                return false;
            }

            template<class Elm>
            void LinkedSortedList<Elm>::print() const
            {
            }

            template<class Elm>
            int LinkedSortedList<Elm>::size() const
            {
                return 0;
            }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
main:

              int main() {

              int value;            // Next list value

              // Create a list
              LinkedSortedList<int> mylist;


              // Load some values
              mylist.insert(7);
              mylist.insert(3);
              mylist.insert(-2);
              mylist.insert(5);


              // Print the whole list
              cout << "Using print():" << endl;
              mylist.print();
              cout << endl;

              // Start over and load new values
              mylist.clear();
              mylist.insert(9);
              mylist.insert(-9);
              mylist.insert(100);
              mylist.insert(12);
              mylist.insert(67);

              // Print the list by repeatedly getting the first value
              cout << "Using getfirst():" << endl;
              while (mylist.getfirst(value))
                cout << value << ", ";
              cout << endl;

              // The list should now be empty.  Prove it using the print
              // function:
              cout << endl << "Final list:" << endl;
              mylist.print();
              cout << endl;

              return 0;
            }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Error:
1>InitializeBuildStatus:
1> Touching "Debug\bensing_jeremy_lab0.unsuccessfulbuild".
1>ClCompile:
1> LinkedSortedList.cpp
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedSortedList<int>::~LinkedSortedList<int>(void)" (??1?$LinkedSortedList@H@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::getfirst(int &)" (?getfirst@?$LinkedSortedList@H@@UAE_NAAH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::clear(void)" (?clear@?$LinkedSortedList@H@@UAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall LinkedSortedList<int>::print(void)const " (?print@?$LinkedSortedList@H@@UBEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedSortedList<int>::insert(int)" (?insert@?$LinkedSortedList@H@@UAE_NH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedSortedList<int>::LinkedSortedList<int>(void)" (??0?$LinkedSortedList@H@@QAE@XZ) referenced in function _main
1>c:\users\owner\documents\visual studio 2010\Projects\bensing_jeremy_lab0\Debug\bensing_jeremy_lab0.exe : fatal error LNK1120: 6 unresolved externals
1>
1>Build FAILED.

I'm using visual studio btw

Thanks!

Member Avatar for jtbens01

I found a solution. The linker error can be fixed a few ways. One way is by including the implementation file in the main.cpp file.
Another way is to create a SortedLinkedList object in the implementation file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.