0

I'm attempting to build a template class Heap that will take any data type and store it in the class wordList (called this because it will ultimately take words as parameters). This is being developed in xCode environment. When heap is called in the main the following error is delivered at compile time.

Error: "heap<std::__1::basic_string<char, std::__1::char_traits<char>, 
std::__1::allocator<char> > >::heap(std::__1::vector<std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> >, 
std::__1::allocator<std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> > > >)", 
referenced from: _main in main.o" 

Is this a problem anyone else has run into and if so how did you resolve it?

Code is presented below:

template <class A_type> class heap
{  
   public:
     heap(vector<A_type> wordlist);
   private:
     vector<A_type> wordList;
};


template <class A_type>
heap<A_type>::heap(vector<A_type> word)
{
    wordList.resize(word.size());
    wordList = word;
}

int main()
{
    vector<string> words;
    string word;
    for (int index=0;index<5; index ++)
    {
        cout << "Enter word";
        cin >> word;
        words.push_back(word);
    }
    heap<string> newHeap(words);
   return 0;
 }

Thanks!

user3451026
  • 61
  • 1
  • 7
  • Sounds like http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – T.C. Feb 22 '15 at 19:29
  • I saw that earlier, unfortunately the errors are not the same but the implementations are quite similar. Which left me more confused. – user3451026 Feb 22 '15 at 19:31
  • Try linking against libc++ manually (add libc++.dylib as 'required' in Target > Build Phases > Link Binary With Libraries) and tell us what happened. – ababababanababab Feb 22 '15 at 20:22
  • After completing this, I received the same error. – user3451026 Feb 22 '15 at 22:39

0 Answers0