参数在某处变为零

时间:2010-05-02 12:18:22

标签: xcode parameter-passing objective-c++

发生了一些非常奇怪的事情:当我调用foo(100 * 1.0f)时,沿着该行的某个地方变为0.要验证我在foo()上放置一个断点,它确实为零,它确实被调用了100 * 1.0F。代码在Obj-C ++中。

这是XCode的GDB前端中的调用函数,如您所见,score * scoreMultiplier为100。 Calling Function http://img341.imageshack.us/img341/1109/screenshot20100502at135.png

void JNPP1PGameController::addScoreToPlayer(NSInteger score) {
    if(!gameOver){
        JNLogString(@"Adding score(%d*%f) to player", score, scoreMultiplier);
        [player addScore: score*scoreMultiplier];
        [wrapper setShouldNotify];
        [wrapper notify];
    } else {
        JNLogString(@"Not adding score(%d*%f) because GAME IS OVAR", score, scoreMultiplier);
    }
}

这是XCode的GDB前端中的被调用函数,这里_score为0。 Called Function http://img156.imageshack.us/img156/1109/screenshot20100502at135.png

- (void) addScore:(NSInteger) _score {
    score += _score;
    JNLogString(@"Player can has %d points.. HURRAY!!!", score);
}

1 个答案:

答案 0 :(得分:0)

通过将调用代码更改为:

来修复代码
void JNPP1PGameController::addScoreToPlayer(NSInteger score) {
    if(!gameOver){
        JNLogString(@"Adding score(%d*%f) to player", score, scoreMultiplier);
        NSInteger _score = score*scoreMultiplier;
        JNLogString(@"This is the case: %d", _score);
        [player addScore: _score];
        [wrapper setShouldNotify];
        [wrapper notify];
    } else {
        JNLogString(@"Not adding score(%d*%f) because GAME IS OVAR", score, scoreMultiplier);
    }
}

我认为现在出现了一个未定义的错误(我得到了一个“找不到方法”警告)参数类型。