c++ - Unable to access static member -> unresolved external symbol i -


this question has answer here:

class test { private:     static int i; public:      static void foo()     {         = 10;     }     static int geti(){ return i; } };  int _tmain(int argc, _tchar* argv[]) {        test::foo();     std::cout << test::geti();     return 0; } 

this simple test, think wrong static use in program. because "unresolved external symbol i". why ?

you have define static member variables outside class definition:

int test::i=10; //or value or definition do. 

in class declaring, not defining. without definition, linker not able find ans show unresolved external symbols.

static member variables in class requires special treatment because of one definition rule , compilation model of c++.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -