I am wondering how a "Managed vector" is declared.
I have worked much with:
std::vector<string> OneVector;

How is the same declared for a Managed type ?

What I am trying to do is to translate this to managed:

std::vector<string> OneVector;
std::string Stuff = "Hello";


At the same time, I do wonder if it is possible to declare something like this in a "Form"
private: std::vector<string> hello;

The compiler says that it is not possible to mix native within managed. This is the reason I do wonder the above.
The thing is that I want 2 buttonControls to share the same vector.
buttoncontrol1 will fill the vector up and buttoncontrol2 will use this "filledup" vector.

I have tried to declare a Vector like this but this does not compile:
The Errormessage says:
only static data members can be initialized inside a ref class or value type

public: System::Collections::Generic::List<String^> OneVector = new System::Collections::Generic::List<String^>();

Then I tried this and it seems to work:

public: System::Collections::Generic::List<String^> OneVector;

List<> is a managed type from the .NET framework. To declare the type you need to make it a managed reference and to instantiate the object you need to use gcnew instead of new:

using namespace System;
using namespace System::Collections::Generic;

int main()
  List<String^>^ OneVector = gcnew List<String^>();

  for (int i = 0; i < 10; ++i)
    OneVector->Add("ABC" + i.ToString() + "XYZ");

  for each (String^ s in OneVector)
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.