Solved

variable outside of method not being incremented

Posted on 2014-04-07
4
169 Views
Last Modified: 2014-04-07
myint is not getting incremented.

myform.cpp file
int myint = 0;

namespace xyz
{
  void myform::MainTimer_Tick(System::Object^ sender, System::EventArgs^ e)
  {
    myint++;
  }
}

Open in new window

There are no Classes, just methods and variables.

So what's going on here?
0
Comment
Question by:deleyd
  • 2
4 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 39984318
Why is it declared outside of the namespace?
0
 

Author Comment

by:deleyd
ID: 39984333
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?
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 39984373
Have you tried

::myint++;

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...
0
 

Author Closing Comment

by:deleyd
ID: 39984489
That's it! [the two colons worked.]

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now