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
[72054] 템플릿클래스 상속 시 소멸자 문제
복정동김서방 [] 3695 읽음    2014-11-30 15:39
안녕하세요.
TList를 좀 편하게 써보려고 아래와 같이 템플릿 클래스로 만들어봤습니다.
===================================================
template <class T>
class TTList : public TList
{
private:
protected:
    T * __fastcall GetItems( int Index );
    void __fastcall SetItems( int Index, T * Item );

public:
    __fastcall TTList( );
    virtual __fastcall ~TTList( );
    void __fastcall Add( T * Item );
    void __fastcall Clear( );
    __property T * Items[ int Index ] =
    {
        read = GetItems,
        write = SetItems
    } ;
} ;
template <class T>
__fastcall TTList<T>::TTList( )
    : TList( )
{
}

template <class T>
__fastcall TTList<T>::~TTList( )
{
    OutputDebugString(L"TTList<T>::~TTList");
    Clear( );
}

template <class T>
T * __fastcall TTList<T>::GetItems( int Index )
{
    return ( T * )TList::Get( Index );
}

template <class T>
void __fastcall TTList<T>::SetItems( int Index, T * Item )
{
    TList::Put( Index, Item );
}

template <class T>
void __fastcall TTList<T>::Add( T * Item )
{
    TList::Add( Item );
}

template <class T>
void __fastcall TTList<T>::Clear( )
{
    for ( int i = 0; i < this->Count; i++ )
    {
        T * Item = ( T * )this->Items[ i ];
        delete Item;
    }
    TList::Clear( );
}
==================================================
그런데 저 리스트에서 특정 기능이 필요해서
TTList를 상속받는 클래스를 정의 했는데 소멸자 쪽에서 자꾸 에러가 납니다.

template <class T>
class TOrderingList : public TTList<T>
{
private:
public:
    __fastcall TOrderingList();
    __fastcall ~TOrderingList();
};

template <class T>
__fastcall TOrderingList<T>::TOrderingList( )
    : TTList<T>( )
{
}

왜 이것만 하면 오류가 날까?
template <class T>
__fastcall TOrderingList<T>::~TOrderingList( )
{
}

TOrderingList 사용 부분
1. 선언
TOrderingList<ORD_ITEM>* m_lstOrdItem;
2. 인스턴스 생성
m_lstOrdItem = new TOrderingList<ORD_ITEM>();

TOrderingList를 TTList로 변경하면 문제 없이 컴파일 되고,
TOrderingList의 소멸자 함수 선언부와 구현부를 모두 주석처리 하면 문제 없이 컴파일 됩니다.
대체 제가 뭘 잘못 한걸까요?

+ -

관련 글 리스트
72054 템플릿클래스 상속 시 소멸자 문제 복정동김서방 3695 2014/11/30
72056     Re: 컴파일러 버그 입니다 빌더(TWx) 3553 2014/12/01
72058         Re:Re: 컴파일러 버그 입니다 복정동김서방 3494 2014/12/01
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.