I'm trying to program a GUI application in C++ and I need 3 variables to be static such that all objects of that type share the same value. I'm receiving the attached error message. The green, red, and blue blocks are placed there by me in a paint application to obstruct the purpose of the application. (A) Green is the project name, (B) blue is an array of integers, and (C) red is the object. The error message is also shown below in text. I also tried removing the static declarer before the declaration and the program did run. How do I resolve this issue?
Note: The link posted above did not resolve the issue. I implemented the proposed solution and received the following error: names followed by a '::' must be a class or namespace name. The code looked like this:
static vector<int> C::B;
and was declared directly after the class definition for B, as specified in the post linked as duplicate question.
[Error Message][1]
[1]: https://i.stack.imgur.com/uwP8v.png
Build started...
1>------ Build started: Project: A, Configuration: Debug x64 ------
1>A.cpp
1>B.cpp
1>Generating Code...
1>B.obj : error LNK2001: unresolved external symbol "public: static class std::vector<int,class std::allocator<int> > B::C" (?C@B@@2V?$vector@HV?$allocator@H@std@@@std@@A)
1>B.obj : error LNK2001: unresolved external symbol "public: static int B::userX" (?userX@B@@2HA)
1>B.obj : error LNK2001: unresolved external symbol "public: static int B::userY" (?userY@B@@2HA)
1>C:\Users\swest\Desktop\C++ Project\A\x64\Debug\A.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "A.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========