trouble with structs

ok im writing a program and in it it has two files im trying to access an array from the second file wich is declared within a struct but when i compile i get 3 errors here is some bits of my code:

file1.h
1
2
3
4
5
struct state
{
int am[12];
//more code
}


file2.cpp
1
2
3
4
5
6
7
8
9
10
11
#include 'file1.h'

int main()
{
switch(type)
{
case CON:
state* am[5] = am[5] + 40;
//more code
}
}


my errors are:
error C2440: 'initializing' : cannot convert from 'state *' to 'state *[5]'
error C2360: initialization of 'am' is skipped by 'case' label
IntelliSense: initialization with '{...}' expected for aggregate object

i am using vc++ 2010

does anyone know how to fix this?

It is unclear what you are trying to do from your example, but this state* am[5] =am[5] + 40; attempts to declare an array of 5 pointers to state structs. am[5] would then be a pointer to a state struct (uninitialized), and you are trying to add 40 to it and then assign this pointer to your array (which is of type state*[5], roughly equivalent to state**). Also, you can not declare variables within a case unless they are enclosed in a block with braces {}.

To access an array in a state struct, you need to have a state struct to start with:
state myState;
Then you would have to use member selection to access the array:
myState.am[5] = myState.am[5] + 40;
or equivalently:
myState.am[5] += 40;
to increment the fifth element by 40.
sorry i made a mistake, my code actually says:

file1.h
1
2
3
4
5
struct fpsstate
{
int am[12];
//more code
}



file2.cpp
1
2
3
4
5
6
7
8
9
10
11
#include 'file1.h'

int main()
{
switch(type)
{
case CON:
fpsstate* am[5] = am[5] + 40;
//more code
}
}

to-may-toes
to-mah-toes
Topic archived. No new replies allowed.