Пишу свой класс для работы с двухсторонними списками. Вот реализация:
| Код | //==============================================================================
#ifndef ALIST_H #define ALIST_H
//==============================================================================
template <class TypeItem> class aItem { public: aItem(){}; ~aItem(){}; public: aItem* next; aItem* prev; TypeItem data; };
//==============================================================================
template <class Type> class aList { public: aList() { items = 0; } ~aList() { alRemoveItems(); } aItem<Type>* alGetLastItem() { if (!items) return 0; aItem<Type>* tmpItem = items; while(tmpItem->next) tmpItem = tmpItem->next;
return tmpItem; } aItem<Type>* alAddItem() { if (!items) { items = new aItem<Type>; return items; } aItem<Type>* tmpItem = this->alGetLastItem(); tmpItem->next = new aItem<Type>; tmpItem->next->prev = tmpItem; return tmpItem->next; } void alRemoveItems() { if (!items) return;
aItem<Type>* tmpItem = alGetLastItem(); aItem<Type>* tmpItem2 = 0; while(1) { tmpItem2 = tmpItem->prev; delete tmpItem; if (tmpItem2) tmpItem = tmpItem2; else break; } items = 0; }
private: aItem<Type>* items; };
//==============================================================================
#endif
//============================================================================== |
При линке выдаёт ошибка, что мол неописанные ссылки на конструктор и деструктор aItem. Почему так?
Добавлено через 4 минуты и 24 секунды Вот так всегда, запостишь тему и разберёшься в ней через пять минут. Конструктор aItem<TypeName>(){}; Деструктор aItem<TypeName>(){}; должны быть. |