[Kget] Refactor transferhandler & transfergrouphandler?

Lukas Appelhans l.appelhans at gmx.de
Thu Aug 14 06:42:41 CEST 2008


Am Dienstag 12 August 2008 23:04:13 schrieb Carsten Pfeiffer:
> Am Mittwoch, 13. August 2008 schrieb Lukas Appelhans:
> > > I thought you would dynamic_cast for TransferGroupHandler instead of
> > > the base Handler class? AFAIK there is no problem to
> > > dynamic_cast<TransferGroupHandler*>(someHandlerPtr)
> >
> > that won't work afaik, dynamic_cast can only cast downwards...
>
> If the hierarchy looks like this:
>
>                 -----------------------
>
>                 | TransferHandlerBase |
>
>                 -----------------------
>                    A               A
>
>          -----------------   ----------------------
>
>          |TransferHandler|   |TransferHandlerGroup|
>
>          -----------------   ----------------------
>
> then the following works just fine:
>
> TransferHandlerBase *handler = getSomeHandler();// returns one of the two
> TransferHandlerGroup *group = dynamic_cast<TransferHandlerGroup*>(handler);
>
> group will be 0 if handler is not of type TransferHandlerGroup *.
> group will be a valid pointer if handler is of type TransferHandlerGroup *.
If it works it would be great, till now I thought:
dynamic_cast<TransferHandlerBase*>(grouphandler);
->valid!

dynamic_cast<TransferGroupHandler*>(handler);
->invalid/compile error!

Lukas
>
> Cheers,
> Carsten



More information about the Kget mailing list