?
Solved

variable outside of method not being incremented

Posted on 2014-04-07
4
Medium Priority
?
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

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 800 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

764 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