1

I'm trying to create an array of b2Vec2 arrays using inline declaration. Right now I have...

    NSMutableArray *array = [[NSMutableArray alloc] init];

    b2Vec2 temp1[] = {
        *new b2Vec2(1,1),
        *new b2Vec2(0,0)
    };

    [array addObject:(id)temp1];

    b2Vec2 temp2[] = {
        *new b2Vec2(1,1),
        *new b2Vec2(0,0)
    };

    [array addObject:(id)temp2];

    b2Vec2 temp3[] = {
        *new b2Vec2(1,1),
        *new b2Vec2(0,0)
    };

    [array addObject:(id)temp3];

Is there any way I can get the temp1, temp2, and temp3 declaration inline with the addObject method call? Something like this...

[array addObject:<some inline array instantiation>];
[array addObject:<some inline array instantiation>];
[array addObject:<some inline array instantiation>];

Thanks!

4

1 回答 1

1

不,你不能那样做。您必须先声明数组 temp1-3,然后才能在[array addObject:]语句中使用它。您可以做的一件事是创建另一个函数来初始化并返回您需要的数组。

于 2012-11-02T03:35:47.957 回答