Undeclared Identifier when trying to reference an object
I created an object array when a button is clicked. When I try to use any of the objects in another function, it is saying that it's an undeclared identifier.
What do I need to do to make sure I can use 'picBlocks[k]' anywhere else in my code?
Object Array created here:
Code:
public: System::Void menuFile_Click(...)
{
PictureBox* picBlocks[] = new PictureBox*[5];
for(int i = 0; i < 5; i++)
{
picBlocks = new PictureBox();
pnlGameField->Controls->Add(picBlocks[i]);
}
}
Trying to access object here in a different function:
bool OtherFunction()
{
if(picBlocks[0] = xxxx) <---says picBlocks is undeclared
{
[I]Blah Blah Blah
}
}
edit:
This is for Visual C++ .NET. It's a Windows Forms Application.
Thanks for the help!
Aaron
Re: Undeclared Identifier when trying to reference an object
make picBlocks a class member.
Re: Undeclared Identifier when trying to reference an object
My apologies. I'm a bit of a beginner. How do I make it a class member?
Re: Undeclared Identifier when trying to reference an object
*bump*
I just need to know how to add picBlocks[j] as a class member. If you need additional code accurately anser this question, I'd be glad to post it.
Thanks
Re: Undeclared Identifier when trying to reference an object
Quote:
Originally Posted by Tineras
*bump*
I just need to know how to add picBlocks[j] as a class member. If you need additional code accurately anser this question, I'd be glad to post it.
Thanks
This is not the .Net forum. Please post this question in the .Net forum.
Regards,
Paul McKenzie
Re: Undeclared Identifier when trying to reference an object
Sorry. I'm still new to programming. I didn't know there was a difference in Visual C++ an Visual C++ .Net
Re: Undeclared Identifier when trying to reference an object
Quote:
Originally Posted by Tineras
Sorry. I'm still new to programming. I didn't know there was a difference in Visual C++ an Visual C++ .Net
What you wrote is not C++ using MFC, ATL, WTL, etc, which this forum deals with. You are using something called "Managed C++" which uses extensions to the C++ language. The Managed C++ questions go in the .Net forum. The name confusion "Visual C++" and "Visual C++ .Net" IMO was a mistake made by Microsoft. You can code traditional C++ programs using Visual C++ .Net, however, what you unknowingly created was a Managed C++ application.
Also, the probable reason why the .Net forum exists, even though what you wrote looks like C++, is that it is confusing when a question is asked here about some weird syntax that doesn't exist in traditional C++. For example, there is no such thing as doing this in C++:
Code:
PictureBox* picBlocks[] = new PictureBox*[5];
This is illegal syntax in C++, but may be perfectly legal using Managed C++.
Regards,
Paul McKenzie