-1

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 ==========
SDW
  • 1
  • 1
  • 1
    Please post your code/errors as text, not images. For people that can't see images for one reason or another your question is unanswerable. We also can't copy the text from images, which stops us from being able to debug your code, i.e., help you. – NathanOliver May 20 '22 at 15:50
  • 3
    For future questions, please do not post images of errors. Copy and paste them into the question (redacting out details if you really need to, or better creating [mcve] that produces such error without giving off details). – Yksisarvinen May 20 '22 at 15:51
  • 1
    Never post plain text like code or error messages as pictures here! Embed it into your markdown using [proper text formatting](https://stackoverflow.com/editing-help#code) instead. – πάντα ῥεῖ May 20 '22 at 15:51
  • Note that, in the linked duplicate, the keyword `static` does *not* appear in the definition of the variable. Nor should it in your added code. – Adrian Mole May 21 '22 at 09:13

0 Answers0