-1

ボードゲームについて少しプログラミングをしていました。「this」を使用して、使用しているオブジェクトをコールバックしていることをメソッドに知らせる方法がわかりません。

-(id)initWithName:(NSString *) name
{
    if (self = [super init])
    {
        name = _name;
    }
    return self;
}

-(void) move:(Dice *) die
{
    [die rollDice];
    [_isOn leave:&Player];
    [_isOn move:&Player using:die remainingSteps:die.totalValue];

}

ご覧のとおり、私は _isOn に "leave:(Player *)p" 関数を実行するように依頼していました。ここで、p は作成されたプレイヤー オブジェクトです。ただし、プログラムは「期待される式」というプロンプトエラーを保持しました

4

1 に答える 1

2

I assume what you are looking for is:

[_isOn leave:self];

Player represents the class itself, while the leave method expects a pointer to an instance of the class. In Objective-C, the self keyword (rather than 'this') refers to the current object instance.

于 2013-09-01T10:40:23.823 に答える