C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[65598] Re:list 와 iterator 구현
이경문 [gilgil] 1702 읽음    2011-11-28 13:36
template class는 실제로 사용( List<int> )할 때 실제로 컴파일이 됩니다. List.h 및 List.cpp로 분리를 해 놓으면 나중에 링크가 되지 않습니다.
List class의 implementation clode를 List.h 하나로 관리하시기 바랍니다(List.cpp를 없애고 전부 List.h로 옮길 것).

leed 님이 쓰신 글 :
: 이중 연결 리스트를 모태로
:
: 템플릿을 사용해서 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 );
: };
: 

+ -

관련 글 리스트
65583 list 와 iterator 구현 leed 2918 2011/11/26
65598     Re:list 와 iterator 구현 이경문 1702 2011/11/28
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.