Solved

variable outside of method not being incremented

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

911 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

15 Experts available now in Live!

Get 1:1 Help Now