const static int....
Am I just being stupid or what?
All I want is a const variable that is shared by every class of the type... a static const. When I have something like:
static const int maxnumofbots = 20;
the compiler saays that only '= 0' can follow... so where would I put the value I want this variable to hold?
[EDIT]
This variable IS in a class
not sure if it was obvious by only indirectly mentioning this
[/EDIT]
Thanx!
Dwiel
[edited by - Tazzel3d on March 6, 2003 4:42:47 PM]
Post the exact code, and the exact error message - also, which compiler are you using?
Your compiler is not standard compliant, what compiler are you using. Do it like this instead:
Definition file (.h):
Implementation file (.cpp):
Or you could do like this in the definition file (.h):
Update GameDev.net system time campaign - success at last
Definition file (.h):
class theclass
{
static const int maxnumofbots;
};
Implementation file (.cpp):
const int theclass::maxnumofbots = 20;
Or you could do like this in the definition file (.h):
class theclass
{
enum { maxnumofbots = 20 };
};
Update GameDev.net system time campaign - success at last
Hey guys, thanx for the help. When I put the variable decleration in the cpp file, everything worked well...
I wish I could have it in the header though where all of that other stuff is...
I''m using MSVC++ 6.0
Thanx again for the help!
Dwiel
I wish I could have it in the header though where all of that other stuff is...
I''m using MSVC++ 6.0
Thanx again for the help!
Dwiel
MSVC6 does not support ''inline'' static const initialization.
You can use the enum trick instead:
struct x
{
enum { maxnumofbots = 20};
};
You can use the enum trick instead:
struct x
{
enum { maxnumofbots = 20};
};
I didn''t think it actually supported any initialization within the class declaration... does it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement