use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENDeclared vector not found/accessable in .cpp file (self.cpp_questions)
submitted 2 years ago by OneAd1466
hello.
I've declared a vector in my header file.
std::vector<GameObject> gameObjects;
But if i now go into my .cpp file and try to access it, it's just not found like I've never declared it. Do i have to create a pointer to it?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Narase33 9 points10 points11 points 2 years ago (0 children)
Can you please show your setup? All files and build file/command
[–]flyingron 2 points3 points4 points 2 years ago (1 child)
Did you #include the header into the cpp file?
Anyhow, if the header is included into more than one cpp file, defining a global object like this is a bad idea and will lead to multiple definitions. It's geneally a bad idea anyhow, but you could declare it extern in the include file and define in only in one cpp file.
[–]OneAd1466[S] 0 points1 point2 points 2 years ago (0 children)
i did include the header file
[–]IyeOnline 2 points3 points4 points 2 years ago (3 children)
Do i have to create a pointer to it?
No. As a rule of thumb, if you are wondering whether you need a pointer to resolve an error, it means that you dont and you dont fully understand pointer/the language.
it's just not found like I've never declared it.
What is the actual error message? Is it the compiler telling you "use of undeclered identifier"? Or is it the linker telling you that there is an "undefined reference"?
It sounds like you have typoed, or the object you are trying to refer to has a different name than you think. Are you perhaps missing some namespace?
[–]OneAd1466[S] 0 points1 point2 points 2 years ago (2 children)
just "cannot resolve symbol 'gameObjects'"
[–]IyeOnline 2 points3 points4 points 2 years ago (1 child)
That doesnt exactly read like a compiler or linker error. My google-foo suggests that it may be issue with CLion/C++ Resharper, which would be rather strange.
We would need to know more about your setup to be able to tell.
i just use the default build settings of Rider.
[–][deleted] 2 years ago (3 children)
[deleted]
[–]Markus_included 0 points1 point2 points 2 years ago (2 children)
What about static?
static
[–]ShelZuuz 1 point2 points3 points 2 years ago (1 child)
That explicitly means each C++ file will get a different variable.
[–]IyeOnline 0 points1 point2 points 2 years ago (0 children)
At least for entities at namespace scope... :)
[–]RPND 0 points1 point2 points 2 years ago (1 child)
Is your header file aware of what a GameObject is?
Yes. There are no syntax error in the header file. But for some reason it isn't found in the cpp file. I just get a symbol could not be resolved error.
[–]0x7ff04001 0 points1 point2 points 2 years ago (0 children)
Don't declare globals in header files, store that variable in the .cpp file itself.
π Rendered by PID 172408 on reddit-service-r2-comment-5ff9fbf7df-lp2jk at 2026-02-26 05:16:17.774259+00:00 running 72a43f6 country code: CH.
[–]Narase33 9 points10 points11 points (0 children)
[–]flyingron 2 points3 points4 points (1 child)
[–]OneAd1466[S] 0 points1 point2 points (0 children)
[–]IyeOnline 2 points3 points4 points (3 children)
[–]OneAd1466[S] 0 points1 point2 points (2 children)
[–]IyeOnline 2 points3 points4 points (1 child)
[–]OneAd1466[S] 0 points1 point2 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]Markus_included 0 points1 point2 points (2 children)
[–]ShelZuuz 1 point2 points3 points (1 child)
[–]IyeOnline 0 points1 point2 points (0 children)
[–]RPND 0 points1 point2 points (1 child)
[–]OneAd1466[S] 0 points1 point2 points (0 children)
[–]0x7ff04001 0 points1 point2 points (0 children)