I implement a hash table and linked list in C ++ (no STL - I donโt ask) using templates, and I am having problems associating them with g ++. If I #include all my .cpp files together, everything works, so my code definitely works, it's just a link that disables me.
I read a bit in the GCC manual about instantiating a template , but was not sure how to apply it.
My problem: I have HashMap<T>and HashEntry<T>for my hash table ( <T>- value - my keys std::strings). My linked list has LinkedList<T>and Node<T>(where <T>is the value).
In my hash map, I have:
template <class T> class HashMap {
...
private:
LinkedList< HashEntry<T> >** buckets;
}
Which gives me a linked list of HashEntry<T>s.
In a separate file, I have a Linked List class declaration:
template <class T>
class Node {
...
private:
T data;
}
template <class T> class LinkedList {
...
private:
Node<T> * first;
}
, ( g++ -c -frepo *.cpp), :
g++ -frepo -o app LinkedList.o HashMap.o
[...unrelated errors about not having a main method - they go away when I link that in]
HashMap.o: In function `HashMap<int>::~HashMap()':
HashMap.cpp:(.text._ZN7HashMapIiED1Ev[HashMap<int>::~HashMap()]+0x65): undefined reference to `LinkedList<HashEntry<int> >::~LinkedList()'
HashMap.o: In function `HashMap<int>::insert(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
HashMap.cpp:(.text._ZN7HashMapIiE6insertESsi[HashMap<int>::insert(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)]+0xff): undefined reference to `Node<HashEntry<int> >::setData(HashEntry<int>)'
Google google, , . HashMap HashEntry ( (template class HashMap< int > template class HashEntry< int >.
, LinkedList Node, HashEntries<int>. , LinkedList.h, #include d Hash. /extern-.
, - , , . ?