struct and classes

Jan 6, 2017 at 3:08pm
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;
};
Jan 6, 2017 at 4:22pm
Line 12 is out of place. When do you want this line of code to execute?
Jan 7, 2017 at 10:06am
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
Jan 7, 2017 at 11:03am
That's because it's inside a function. Outside of functions you can only declare and define things.
Jan 7, 2017 at 12:19pm
doesnt matter now.... thanks for the help though
Topic archived. No new replies allowed.