blipman17 blipman17 - 7 months ago 35
C++ Question

what's the proper way to declare static mutable values

I've got a mutable static value in my program.

static int foo = 0;

regardless of private or public accessibility I don't want nasty name collisions.
I don't like things just sitting in the scope of my namespace.
So I tried the following

class aClass{
static int foo = 0;

Apperantly this is impossible, unless I don't assign a variable to
Which is impossible for foo in my program.

What is the standard on declaring mutable statics with a default value?
I read something about people using
const <T>*
but that doesn't sound sane to me, and seems prone to error.


how about header:

class aClass {
  static int foo;

cpp file

int aClass::foo;

you can then add an initialisation if you want to there.