루프에 dynamic_cast
을 넣어도 되나요?루프에 dynamic_cast 넣기
//Searches for the reservation with the given reservation number, and //deletes it. Uses the confirmReservation function if the reservation to be //deleted was an OK one
void cancelReservation(string resNum)
{
for (int i=0;i<seats+waitingListMax;i++)
{
for (int seat=i;seat<seats;seat++)
{
Ok* okptr=dynamic_cast <Ok*>(reservations[seat]);
}
for (int wait=seats;wait<seats+waitingListMax;wait++)
{
Waiting* waitingptr=dynamic_cast <Waiting*>(reservations[wait]);
}
if ((reservations[i]!=0) && (reservations[i]->getReservationNumber()==resNum))
if (okptr)
{
//doing somting
}
if (waitptr)
{
//doing somthing else
}
}
왜 괜찮지 않습니까? 내 말은, 당신의 코드는 동일한 포인터 시간과 시간을 다시 덮어 쓰지만, 캐스트 자체는 괜찮습니다. –
정확히 무엇을하려하고 있습니까? 루프가 완료된 직후에 파손되는 변수에 각 캐스팅을 덮어 씁니다. –
괜찮 았지만 수행 한 방식이 아닙니다. 캐스트가 덮어 쓰여 지므로 마지막 캐스트 만 남습니다. – iammilind