Solved

variable outside of method not being incremented

Posted on 2014-04-07
4
173 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 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

730 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