As the Troll mentioned, you can set constant members in the constructor like so:

class MyClass
{
public:
MyClass() : cvar(5)
{
}

private:
const int cvar;
};

If you're going to use a constant data member, however, you should declare it as static. That way all instances of an object only share that one constant rather than every instance having their own version and all of them being the same.

class MyClass
{
private:
static const int cvar;
};

Remember to define the static somewhere in your sources or you will get a linker error:

const int MyClass::cvar = 5;

Hope this helps

11-01-2001

zen

..or you could use an enum to guarantee that it will be evaluated at compile time and not have storage allocated (as MSVC 6.0 doesn't support initialisation of static consts from within class declarations) -