I'm running into some compiler errors I don't understand. I'm pretty sure I'm doing something very wrong here but I don't know what. I would like all the world constants to be defined as belonging to the class.
Notes:
I'm only using classes as structs with attached members. I'm not following strict Object-Orriented Design on purpose. Please do not comment the public variables.
I'm not concerned very much about the compiler inlining stuff. I'm using this structure because it's easy for me to use. (If it worked)
class Board{
public:
enum PhysicsResult{ BOUNCE, OUT_OF_BOUNDS_TOP, OUT_OF_BOUNDS_BOTTOM, CONTINUE };
//World constants
const static float Height = 500;
const static float Width = 300;
//ERROR: 'Board::Width' cannot appear in a constant-expression.
const static float PaddleWidth = Width/15;
const static float BallRadius = 5;
const static float BounceDistance = 1.5;
//World Objects
Ball ball;
Paddle paddle1;
Paddle paddle2;
/*
1---2
| |
0---3
*/
//ERROR: a brace-enclosed initalizer is not allowed here before '{' token
//ERROR: invalid in-class initalization of static data member of nonintegral type 'const Pair[4]'
const static Pair corners[4] = {Pair(0, 0), Pair(0, Height), Pair(Width, Height), Pair(Width, 0)};
//ERROR: a brace-enclosed initalizer is not allowed here before '{' token
//ERROR: invalid in-class initalization of static data member of nonintegral type 'const Pair[2]'
const static Pair left_wall[2] = {corners[0], corners[1]};
//ERROR: a brace-enclosed initalizer is not allowed here before '{' token
//ERROR: invalid in-class initalization of static data member of nonintegral type 'const Pair[2]'
const static Pair right_wall[2] = {corners[3], corners[2]};
//ERROR: a brace-enclosed initalizer is not allowed here before '{' token
//ERROR: invalid in-class initalization of static data member of nonintegral type 'const Pair[2]'
const static Pair top_wall[2] = {corners[1], corners[2]};
//ERROR: a brace-enclosed initalizer is not allowed here before '{' token
//ERROR: invalid in-class initalization of static data member of nonintegral type 'const Pair[2]'
const static Pair bottom_wall[2] = {corners[0], corners[3]};
If it is possible to do this, what is the proper syntax for doing this? If this is not possible, what alternative should I use?