1

my YYY.h file is


 #define W 1 // i am
 #define B 2 // opponent
 #define F 3 // board margin
static int boardPos[12][12];
@interface YYY : NSObject 
{...}
-(id)init;
@end

and YYY.m is


#import "YYY.h"


@implementation YYY

-(id)init
{   
    if (self = [super init]) {

        // initializing Empty Board

        boardPos[12][12] = {
            {F,F,F,F,F,F,F,F,F,F,F,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,0,0,0,0,0,0,0,0,0,0,F},
            {F,F,F,F,F,F,F,F,F,F,F,F}
        };
...

I got error "Expected expression before { token in "boardPos[12][12] = {" string. If I write something before boardPos - it become local variable; So I cant initialize this C-array properly. I need boardPos be visible in class scope. I tried to put it in class declaration - same error.

Btw, I already rewrite it on NSArray objects but still interesting how to deal with C-arrays.

Thx!

2 Answers 2

5

I think you should write this in .m file

static int boardPos[12][12] = {
        {F,F,F,F,F,F,F,F,F,F,F,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,0,0,0,0,0,0,0,0,0,0,F},
        {F,F,F,F,F,F,F,F,F,F,F,F}
    };

and remove static int boardPos[12][12]; in .h, remove boardPos[12][12] = { ... } in .m.

This will make boardPos visiable only in this .m file.

Sign up to request clarification or add additional context in comments.

Comments

3

the array initialization has to be done as part of a declaration, i.e.:

in b[12] = {...};

it's not possible within a dynamic assignment...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.