C++ Static Variable Issues
Hi there! I'm currently having some issues when attempting to make a static variable. I have experience in Java and so my understanding of a static variable is something that affects every object of a class and is the same for each object. I am trying to do this for a boolean as shown in the code:
However I'm not entirely sure how to initialize the boolean. Whenever I try I just get a compiler error screaming at me for an unidentified variable. I would love if one of you guys could give me a hand in figuring this out.
asked Nov 01 '16 at 07:47 PM in C++ Programming
One thing you could try is to declare the variable inside of the function that you're looking to use it in. When I did that it seemed to work fine for me.
What I did was create the variable at the top of the .cpp file and then I was able to use it throughout the functions that I wanted to use it in without any compiler errors.
Here's some good reading regarding the static keyword also, if you're interested: http://thesmithfam.org/blog/2010/06/12/the-many-meanings-of-the-c-static-keyword/
Have a great day
answered Nov 03 '16 at 01:44 PM
Sean L ♦♦ STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here