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> ^'
with
[
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:

"
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
Thanks

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.