hi,i am trying to make a global integer array of size 32 in Windows forms.I am Using Visual Studio C++ 2008.
here is my code:

array<Int32^> ^garray = gcnew array<Int32^>(32);

if i declare it globally then it gives the following error:
"error C3145: 'garray' : global or static variable may not have managed type 'cli::array<Type> ^'
Type=System::Int32 ^
may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap"

and if i declare it in private then:

error C3845: 'GuiTesting::Form1::garray': only static data members can be initialized inside a ref class or value type

can anybody tell me how to make it?...i am new to gui

8 Years
Discussion Span
Last Post by William Hemsworth

I would recommend creating it as a data member of the parent form class and then passing it around as necessary. Globals are tricky to get right.


Careful where you are placing that code, the easiest option would be to find where it says:

/// Required designer variable.

(line 49 for me on my default generated window)
Then put any variables after that. Also, it's not usually a problem to declare it as a static variable, which should allow it to compile.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.