2011-02-08 60 views
0

的dynamic_cast我想寫在目標C的代碼:如何在目標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 ; 
} 

球ElementJeu的子類... 是否在OBJ-C類似的東西存在?

謝謝

回答

3

你不需要它。 Objective-C知道你的對象的類型。

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

PS:jeu是多餘的。

+2

通常setter/getter對將被設置爲Vx:並且vx不是getVx – 2011-02-08 13:26:44