|
복정동김서방 님이 쓰신 글 :
: 안녕하세요.
: 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의 소멸자 함수 선언부와 구현부를 모두 주석처리 하면 문제 없이 컴파일 됩니다.
: 대체 제가 뭘 잘못 한걸까요?
:
답변...
템플릿 코드에 문제가 있는 게 아니고... 컴파일러 자체의 버그 입니다.
엠바 컴파일러 팀에선 C++ Template과 Delphi Generic상의 차이때문이라는 엉뚱한 궤변을 늘어 놓고 있는데
TTList는 deduction과 템플릿 instance 가 정상적으로 되는데 상속 레이어 하나 더 두었다고 해서...
TOrderingList 으로는 사용할 수 없다는 건 말도 안되는 얘기죠.
해결방법은 두가지가 가능한데...
1.
Template deduction/instance 를 제대로 파싱처리하는 64비트 버전 컴파일러를 이용해서 컴파일 하든가 (clang 버전 bcc64)...
2.
아니면 TTList 템플릿을 구현할 때... TList 를 상속하는 방법을 사용하지 말고...
template<class T>
class TTList
{
private:
TList *pList;
public:
__fastcall TTList( ){}
__fastcall virtual ~TTList( ){}
};
template <class T>
class TOrderingList : public TTList<T>
{
public:
__fastcall TOrderingList() {}
__fastcall virtual ~TOrderingList() {}
};
위와 같이 TList를 TTList에 Agregate 해서 구현 하세요.
이왕 clang 소스코드 베껴서 파는거, 32비트 버전도 clang 베껴서 팔든가... 엠바 컴파일러 툴은 문제가 참 많아요...
|