Я впервые использую шаблоны в C ++ и сталкиваюсь с проблемой при попытке компиляции.В основном пытаюсь создать свой собственный базовый ArrayList:
.hpp:
#ifndef ARRAYLIST_HPP_
#define ARRAYLIST_HPP_
template <class T>
class ArrayList
{
private:
int current, top ;
T * al ;
public:
ArrayList() ; // default constructor is the only one
};
#endif /* ARRAYLIST_HPP_ */
.cpp:
#include "ArrayList.hpp"
using namespace std ;
//template <class T>
//void memoryAllocator( T * p, int * n ) ; // private helper functions headers
template <class T>
ArrayList<T>::ArrayList()
{
current = 0 ;
top = 10 ;
al = new T[top] ;
}
Основной:
#include "ArrayList.hpp"
int main()
{
ArrayList<int> test ;
}
Когда я пытаюсь собрать без основного, он прекрасно компилируется, однако, как только я пытаюсь использовать его в основном, я получаю следующую ошибку:
Undefined symbols for architecture x86_64:
"ArrayList<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::ArrayList()", referenced from:
_main in Website.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [APProject2] Error 1
Любые мысли о том, чтоможет быть, проблема будет высоко ценится!
Ура!