I wish to access a static variable declared in a class. Following this post's suggestions, I defined two files,
in test.h:
class foo
{
private:
static int i;
};
in test.cpp:
#include "test.h"
int main(int argc, char* argv[]){
int foo::i = 0;
}
But, the compiler still generates this error when I do make test
. I'm using a mac:
test.cpp:16:11: error: definition or redeclaration of 'i' not allowed inside a function
int foo::i = 0;
How can I fix it?