variable outside of method not being incremented

myint is not getting incremented.

myform.cpp file
int myint = 0;

namespace xyz
  void myform::MainTimer_Tick(System::Object^ sender, System::EventArgs^ e)

Open in new window

There are no Classes, just methods and variables.

So what's going on here?
Who is Participating?
jkrConnect With a Mentor Commented:
Have you tried


Open in new window


>>Maybe I should move that variable inside the namespace?

That would definitely be an option - except if other code in other namespaces uses it as well...
käµfm³d 👽Commented:
Why is it declared outside of the namespace?
deleydAuthor Commented:
Beats me. I inherited this code.

Interesting it compiles and runs without complaint. If I right-click on myint++ and say "Go to Definition" it goes to the definition above.

Maybe I should move that variable inside the namespace? Or declare it static?
deleydAuthor Commented:
That's it! [the two colons worked.]

(I also discovered there was another static int myint = 0; at the top of the method.)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.