///header
class C {
private:
staticint i;
public:
void set_i(int j);
};
///cpp
int C::i=0;
void C::set_i(int j){i=j;}
///main
//...
int N=atoi(argv[1]);
//here I want to access C::i *before* creating a C-object (so I can't use set_i yet)
Yes, you don't need objects to access static members, but you need to be in a friend class/function if it's private
if method set_i only modifies the static member should be static too
So I need to define either a static (friendly to C) function outside everything or a static function inside another (friendly to C) class ?
EDIT : or just this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
///header
class C {
private:
staticint i;
public:
staticvoid set_i(int j);
};
///cpp
int C::i=0;
void C::set_i(int j){i=j;}
///main
//...
int N=atoi(argv[1]);
C::set_i(N);
//simple as that ?!