Solved

variable outside of method not being incremented

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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