开发者

How to dynamic_cast in objective c

I'd like to write this code on objective c:

    bool BordVertical::collisionwith( Jeu& jeu, ElementJeu& element )
{
    // Verify if the element is balle ype
    Balle* balle = dynamic_cast<Balle*>( &element ) ;
    if( balle )
    {
        balle->Vx( -balle->Vx() ) ;
        return true ;
    }
    return false ;
}

ball is a subclass of ElementJeu... Does anything similar exist in obj-c?

Than开发者_StackOverflowks


You don't need it. Objective-C knows the type of your objects.

- (BOOL) collisionwith:(ElementJeu*)element {
    if ([element isKindOfClass:[Balle class]]) {
        [element setVx:[element getVx]];
        return YES;
    }
    return NO;
}

PS: jeu is redundant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜