Array initialization in managed C ++

I want to declare and initialize a 1D managed array of elements.

If it was C # code, I would write it like this:

VdbMethodInfo[] methods = new VdbMethodInfo[] { new VdbMethodInfo("Method1"), new VdbMethodInfo("Method2") }; 

I'm trying to write (well, actually, I'm writing a program), the same thing in managed C ++ ...

So far I:

 typedef array<VdbMethodInfo^, 1> MethodArray; // How do I avoid pre-declaring the size of the array up front? MethodArray^ methods = gcnew MethodArray(2); methods[0] = gcnew VdbMethodInfo("Method1"); methods[1] = gcnew VdbMethodInfo("Method2"); 

There are two problems with this:

  • This is more detailed.
  • I need to declare the size of the array in front, which is inconvenient for my code generator

Is there an array initialization syntax for GC arrays in Managed C ++? What is the correct syntax? Is there a good web link for this and other similar questions?

+5
c ++ managed-c ++
source share
2 answers

The C ++ / CLI script declares and initializes the syntax differently than in C #. Here is an example ...

 array<String^>^ myArray = gcnew array<String^> {"first", "second"}; 
+25
source share
0
source share

All Articles