|
이 동네 Tip'N Tricks 에 있는 "동적 생성된 컴퍼넌트를 TList에서 삭제"에
있는 내용을 보고 생각난 것인데요.
TList object에 어떤 type의 instance들을 만들어 쓰는 아래의 예는
Tip'N Tricks 14번에 있던 것입니다.
TList *MyButtonList = new TList;
for(int i=0; i<100; i++)
{
TButton *TempButton = new TButton(this);
TempButton->Parent = this;
MyButtonList->Add(TempButton);
}
이 경우 컴퍼넌트 삭제는 다음과 같이 해야 합니다.
while(MyButtonList->Count)
{
delete dynamic_cast<TButton *>(MyButtonList->Items[0]);
MyButtonList->Delete(0);
}
그,런,데,
dynamic_case operator를 쓰지 않고 그냥 포인터타입을 casting하면 안될까요?
delete (TButton *)(MyButtonList->Items[0]);
컴파일 해 본 결과로는 전통적인 casting을 한 아래의 경우에는 제대로 되는데
오히려 dynamic_cast 연산자를 쓴 경우에는 컴파일 에러가 발생하는군요.
[BC++4, Error] E2307 Type 'void' is not a defined class with virtual functions.
→A dynamic_cast was used with a pointer to a class type that is either undefined,
or doesn't have any virtual member functions.
어케된 것인지...
청담동에서
최성규
|