tags:

views:

260

answers:

4

Hello,
I have this code inside a class:

void SendStones()
{
    int currenthole = hole;
    int lastplace = 0;
    for(int i=0;i<stns.size();i++)
    {
        while(1)
        {//Calculate new currenthole
            if(currenthole == 13) { currenthole = 7; break;}
            if(currenthole == 14) { currenthole = 6; break;}
            if((currenthole<=12 && currenthole > 7) || (currenthole<=6 && currenthole > 1)) { currenthole--; break;}
        }
        lastplace = stns.size()-1;
        hole[currenthole]->ReciveStone(stns[lastplace]);//PROBLEM
        stns.pop_back();
    }
}

vector<Stones*> stns;

so it makes this error: invalid types `int[int]' for array subscript

what's the problem?i don't understand. Thanks.

+2  A: 

It looks like hole is a simple int, and you're trying to subscript it. Is that what you mean to do? Where is hole declared?

Adam Bellaire
A: 

Hole is a really big class,
SendStones is a function member in the class.
I won't send the whole file but i can say that
hole[currenthole] is a Hole *hole[14];
It's a big program and project so i sent the related code needed.

Here's the code of the ReciveStones function:



void ReciveStone(Stone *rcvstone) { stns.push_back(rcvstone); }

A: 

oh nvrm,i've founded that error thank you very much.

A: 

Based on what you said in your answer, hole is a pointer to n Hole objects. That means your code isn't doing what you think it's doing.

int currenthole = hole;

This is storing an address value pointing to the first object in your array collection, which means that this code

if(currenthole == 13) { currenthole = 7; break;}
            if(currenthole == 14) { currenthole = 6; break;}
            if((currenthole<=12 && currenthole > 7) || (currenthole<=6 && currenthole > 1)) { currenthole--; break;}

is probably nonsense.

It doesn't explain why you're getting the "invalid types `int[int]' for array subscript" error. Are you sure that there's not a second declaration of type int named hole?

--Actually, re-reading what you wrote, I'm even more certain you're not doing what you think you're doing. SendStones is a member of the class Hole, correct? Check that your Hole class doesn't have a hole member variable inside it. That is probably the problem, since it will be found before any global variable called hole (if I remember my scoping rules correctly).

mos