const static int....

Started by
4 comments, last by Dwiel 21 years, 1 month ago
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]
Advertisement
Post the exact code, and the exact error message - also, which compiler are you using?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Your compiler is not standard compliant, what compiler are you using. Do it like this instead:

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
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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
MSVC6 does not support ''inline'' static const initialization.

You can use the enum trick instead:

struct x
{
enum { maxnumofbots = 20};
};
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I didn''t think it actually supported any initialization within the class declaration... does it?

This topic is closed to new replies.

Advertisement