struct and classes

just a simple question, is it possible to do this
1
2
3
4
5
6
7
8
9
10
11
12
13
struct position
{
    int x;
    int y;
} player, object;

class map
{
private :
    const static int height = 20;
    const static int width = 40;
    player.x = (height - 1)/2;
};
Line 12 is out of place. When do you want this line of code to execute?
not sure if I understand what you mean by when this line of code to execute but
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
struct position
{
    int x;
    int y;
};
position player, object;

class map
{
private :
    const static int height = 20;
    const static int width = 40;
    player.x = (height - 1)/2;
};

int main()
{
    player.x = (40 - 1)/2;
}

the player.x in int main has no trouble at all
That's because it's inside a function. Outside of functions you can only declare and define things.
doesnt matter now.... thanks for the help though
Topic archived. No new replies allowed.