blipman17 blipman17 - 1 year ago 58
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.

Answer Source

how about header:

class aClass {
  static int foo;

cpp file

int aClass::foo;

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download