Выкидывает подряд ошибки: Ошибка 2 error LNK2019: ссылка на неразрешенный внешний символ "public: __thiscall Array<int>::~Array<int>(void)" (??1?$Array@H@@QAE@XZ) в функции _main C:\Code\test\test\main.obj Ошибка 1 error LNK2019: ссылка на неразрешенный внешний символ "public: __thiscall Array<int>::Array<int>(int)" (??0?$Array@H@@QAE@H@Z) в функции _main C:\Code\test\test\main.obj Может кто подскажет, в чем причина и как ее исправить? Код main.cpp: | Код | #include <iostream> #include <conio.h> #include <C:\\Code\test\test\ArrayDLL.h>
void main() { int checked=0; Array<int>test(5); while(checked!=5) { std::cout<<"1. Add Element"<<std::endl; std::cout<<"2. Delete Element"<<std::endl; std::cout<<"3. Add Element"<<std::endl; std::cout<<"4. Print array"<<std::endl; std::cout<<"5. Exit"<<std::endl; std::cout<<"Your choice: "; std::cin>>checked; switch(checked) { case 1: case 2: case 3: case 4: break; } } }
|
ArrayDLL.h: | Код |
#include <iterator> #include <stdexcept> class OutOfRange {}; class GetEmptyException {};
template <class T> class Array { private: T* arr; // непосредственно сам массив int size; // размер массива int last; // последний итерируермый элемент int next; // следующий итерирурем элемент int length; // кол-во элементов (которые имеются в массиве) public:
Array(int sizeArray);
void AddElementByValue(const T item); // добавление элемента в конец void DeleteElementByValue(const T item); // удаление элемента void AddElementByIndex(int index, const T item); // добавление элемента по индексу void DeleteElementByIndex(int index); // удаление элемента по индексу
void Print(); // вывод содержимого массива в консоль void Clear(); // очистка массива
~Array(); };
|
ArrayDLL.cpp: | Код | #include <C:\\Code\test\test\ArrayDLL.h> #include <iostream> #include <stdexcept>
/* Конструктор класса: создает массив размером sizeArray */ template<class T> Array<T>::Array(int sizeArray) { try { if (sizeArray>0) { arr = new T[sizeArray]; size = sizeArray; last = NULL; next = 0; length = 0; } else throw 1; } catch(int error) { switch(error) { case 1: std::cout<<"Argument less than zero!..."<<std::endl; break; } } catch(bad_alloc) { std::cout<<"Not enough memory!..."<<std::endl; } catch(...) { std::cout<<"Undefined exception!..."<<std::endl; } }
/* Добавление элемента в массив */ template<class T> void Array<T>::AddElementByValue(const T item) { if (last<size) { last = (last+1)%size; length++; arr[last]=item; } else { int i; newArray = new T[size+1]; for(i=0; i<size; i++) newArray[i]=arr[i]; delete arr; arr=newArray; delete newArray; last = (last+1)%size; length++; arr[last]=item; } }
/* Удаление элемента из массива по содержимому */ template<class T> void Array<T>::DeleteElementByValue(const T item) { bool found=false; int i, count; // найдем элемент; запомним индекс, если нашли for(i=next%size, count=1; count<=length; i=(i+1)%size, count++) { if (arr[i]==item) { found=true; break; } } // сместим элементы на одну позицию if(found) { for(; count<=length; count++) arr[i]=arr[i+1]; arr[length]=0; length--; } else std::cout<<"Element not matched..."<<std::endl; }
/* Вывод содержимого массива в консоль */ template<class T> void Array<T>::Print() { if (length==0) { std::cout<<"Array is empty"<<std::endl; return; }
int i,count; for(i=next%size, count=1; count<=length; i=(i+1)%size, count++) std::cout<<arr[i]<<" "; std::cout<<std::endl; }
/* Очистка массива от данных */ template<class T> void Array<T>::Clear() { delete arr; arr = new Array[size]; last = NULL; next = 0; length=0; }
|
Это сообщение отредактировал(а) Relrin - 20.12.2012, 11:46
|