이중 연결 리스트를 모태로
템플릿을 사용해서 list와 iterator를 구현해보려고 했는데
어쩐지 이상한 오류가 잔뜩 뜨네요...
링커할 때의 오류인거 같은데... 뭔지 잘모르겠어서 올립니다
우선 소스코드 전체는 압축파일로 올리겠습니다.
좀... 길어서요 ;;
Visual Studio 10 에서 출력된 오류 내용
1>TestMain.obj : error LNK2019: unresolved external symbol "public: __thiscall List::~List(void)" (??1?$List@H@@QAE@XZ) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: int __thiscall Iterator::operator*(void)" (??D?$Iterator@H@@QAEHXZ) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Iterator::operator!=(class Iterator const &)const " (??9?$Iterator@H@@QBE_NABV0@@Z) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: class Iterator __thiscall List::end(void)" (?end@?$List@H@@QAE?AV?$Iterator@H@@XZ) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: class Iterator __thiscall Iterator::operator++(int)" (??E?$Iterator@H@@QAE?AV0@H@Z) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: class Iterator const & __thiscall Iterator::operator=(class Iterator const &)" (??4?$Iterator@H@@QAEABV0@ABV0@@Z) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: class Iterator __thiscall List::begin(void)" (?begin@?$List@H@@QAE?AV?$Iterator@H@@XZ) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall List::pushFront(int const &)" (?pushFront@?$List@H@@QAEXABH@Z) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall List::pushBack(int const &)" (?pushBack@?$List@H@@QAEXABH@Z) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Iterator::Iterator(void)" (??0?$Iterator@H@@QAE@XZ) referenced in function _main
1>TestMain.obj : error LNK2019: unresolved external symbol "public: __thiscall List::List(void)" (??0?$List@H@@QAE@XZ) referenced in function _main
1>c:\documents and settings\leed\my documents\visual studio 2010\Projects\student2\Debug\student2.exe : fatal error LNK1120: 11 unresolved externals
소스코드
// 노드 클래스의 본문
template< typename NODETYPE >
class ListNode
{
// 리스트 클래스와 이터레이터 클래스를 friend로 선언
friend class List< NODETYPE >;
friend class Iterator< NODETYPE >;
public:
// 사용자 타입을 정의
typedef NODETYPE value_t;
typedef NODETYPE& refer_t;
typedef ListNode< NODETYPE > node;
ListNode( const value_t & ); // 생성자
value_t getData() const; // 노드의 데이터를 리턴
protected:
value_t data; // 노드의 데이터
node* nextPtr; // 다음 노드의 포인터
node* prevPtr; // 이전 노드의 포인터
};
// 이터레이터 클래스의 본문
template< typename NODETYPE >
class Iterator
{
// 리스트 클래스를 friend로 선언
friend class List< NODETYPE >;
public:
// 사용자 타입을 정의
typedef NODETYPE value_t;
typedef ListNode< value_t > node;
typedef Iterator< value_t > self;
Iterator(); // 생성자
Iterator( node* ); // 노드 포인터 참조 생성자
value_t &operator *(); // 데이터 간접 접근 연산자
node* operator ->(); // 노드 포인터 접근 연산자
const self &operator =( const self & ); // 대입 연산자
// 비교 연산자
bool operator ==( const node * ) const;
bool operator ==( const self & ) const;
bool operator !=( const node * ) const;
bool operator !=( const self & ) const;
// 증감 연산자
self &operator ++();
self operator ++( int );
self &operator --();
self operator --( int );
protected:
node* nptr; // 노드 포인터
};
// 리스트 클래스의 본문
template< typename NODETYPE >
class List
{
public:
// 사용자 타입을 정의
typedef NODETYPE Type;
typedef ListNode< Type > node;
typedef Iterator< Type > iterator;
List(); // 생성자
List( const List & ); // 복사 생성자
~List(); // 소멸자
iterator begin(); // 리스트의 head
iterator end(); // 리스트의 tail->next ( 리스트 마지막에 삽입하기 위한 위치 )
Type &getFront(); // 리스트의 head의 데이터
Type &getBack(); // 리스트의 tail의 데이터
void pushFront( const Type & ); // 앞에서 데이터를 푸시
void pushBack( const Type & ); // 뒤에서 데이터를 푸시
void popFront( Type & ); // 앞에서 데이터 팝
void popBack( Type & ); // 뒤에서 데이터 팝
void add( iterator, const Type & ); // 이터레이터를 참조하여 데이터 삽입
void erase( iterator, Type & ); // 이터레이터를 참조하여 데이터 삭제
void insert( int, const Type & ); // 위치값을 참조하여 데이터 삽입
void remove( int, Type & ); // 위치값을 참조하여 데이터 삭제
bool isEmpty() const; // 리스트가 비어있는가?
int GetSize() const; // 리스트의 노드 개수를 리턴
virtual void print() const; // 리스트를 출력
virtual void sort() const; // 리스트를 정렬 ( default = Quick Sort )
void swap( iterator, iterator ); // 두 노드를 스왑( Data만 바뀜 )
protected:
int size; // 리스트의 노드 개수
node imply; // 리스트의 노드 ( imply->nextPtr = head, imply->prevPtr = tail )
// 새로운 노드를 생성하는 유틸리티 함수
node *getnewNode( const Type & );
// 정렬을 위한 퀵소트 함수
virtual void QuickSort( iterator, iterator );
};
|