I have a small class called Stuff in which I want to store things. These things are int type lists. In all my code, in any classes that I use, I want to have access to these things inside the Stuff class.
main.cpp:
#include "Stuff.h" int main() { Stuff::things.push_back(123); return 0; }
Stuff.h:
#include <list> class Stuff { public: static list<int> things; };
but I get some build errors with this code:
error LNK2001: unresolved external symbol "public: static class std :: list <int, class std :: allocator <int> Stuff :: things" (? things @Stuff @@ 2V? $ list @HV? $ allocator @H @ std @@@ std @@ A) Main.obj CSandbox
fatal error LNK1120: 1 unresolved external elements C: \ Stuff \ Projects \ CSandbox \ Debug \ CSandbox.exe CSandbox
I'm a C # guy, and I'm trying to learn C ++ for a side project. I think I don't understand how C ++ treats static members. So please explain that I am not here.
c ++ static
Mr bell
source share