Undeclared identifier.

Hello. I'm an absolute beginner at c++ and I could need some help with a problem of mine.
I made a little "game" so to speak and I'm trying to make a label that shows the user of this "game" a number everytime the user press a specific button.

I'm using Microsoft Visual c++ 2010 Express and the project is in "Windows Form".

1
2
3
4
5
6
7
8
9
10
11
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)
			 {
			int succeed = 0;
			label3->Text = Convert::ToString(succeed);	
			 }


private: System::Void pictureBox1_DoubleClick(System::Object^  sender, System::EventArgs^  e)
		 {
			succeed=+1;
		 }


And this returns the error message " 'succeed' : Undeclared identifier" when I'm trying to run it.

Thank you for reading this and I would be grateful if you could please help me.
Last edited on
1
2
3
4
private: System::Void pictureBox1_DoubleClick(System::Object^  sender, System::EventArgs^  e)
		 {
			succeed=+1;
		 }


Inside a function, the following variables exist:

Any global variables.
Any variables passed into the function.
Any variables created inside the function.
If the function is a class function, any class variables of that class.

In the function above succeed is not a global function, was not passed into the function, was not created in the function, and the function is not a class function. So the variable succeed does not exist in the function.

In the other function, you have this:
int succeed = 0;
which creates the variable succeed within that function.


Also, this isn't C++. Looks like some kind of Microsoft .NET or managed language.

Edit: I am SO ninjar!
Last edited on
Probably this error message comes from line 10.

the variable succeed is not visible on line 10. It's scope is from line 2 to line 5. It's only visible on those lines.

Make it a member of the enclosing class.
Last edited on
You use variable succeed in function pictureBox1_DoubleClick

succeed=+1;

but it is not declared in this function.
Your succeed is not a global variable, it is specific to the first function. Make it outside the function Form1_Load().
Thank you everyone ^^.
I managed to fix it but now I encountered a problem, once I double click on "pictureBox1" the variable succeed does not add +1.

Any ideas why?

1
2
3
4
private: System::Void pictureBox1_DoubleClick(System::Object^  sender, System::EventArgs^  e)
		 {
			succeed=+1;
		 }


And for Moschops. Like I told you guys before, I'm using Microsoft Visual c++ 2010 Express.
Last edited on
The expression

succeed=+1;

means

succeed = +1;

that equivalent to

succeed = 1;

You have to write

succeed += 1;

or either

succeed++;

or

++succeed;
Last edited on
Thank you Vlad but that does not seem to fix the problem.

Here's my current code:

1
2
3
4
5
6
7
8
9
10
11
12
13
int succeed = 0;


	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)
			 {
			label3->Text = Convert::ToString(succeed);	
			 }

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		 {
			 succeed++;
		 }


I cut out the unnecessary part of the code.
I do not see any problem with the code.
And for Moschops. Like I told you guys before, I'm using Microsoft Visual c++ 2010 Express.


Do you think we don't know what we're talking about? Here's something truly incredible; sometimes, the NAME of something is not a complete description of what it does. I know! Amazing, right?

You are not coding in C++. Don't take it personally. That's a choice you made. It's fine. It just seems silly for you to not know what language you're programming in. Now you know; not C++. Something similar, but not the same.
Topic archived. No new replies allowed.