Need help converting Array of Member Variable to Vector

Consider the following class:

namespace GuiAppTest01 {
	public ref class CatClass {

	private:
		System::Windows::Forms::GroupBox^  groupBox1;

	public:
		void AddCat(System::Windows::Forms::Panel^ Panel);
	};

	void CatClass::AddCat(System::Windows::Forms::Panel^ Panel)  {
		this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
		this->groupBox1->Parent = Panel;
		this->groupBox1->Dock = System::Windows::Forms::DockStyle::Top;
		this->groupBox1->Location = System::Drawing::Point(0, 0);
		this->groupBox1->Name = L"groupBox1";
		this->groupBox1->Size = System::Drawing::Size(20, 40);
		this->groupBox1->TabIndex = 0;
		this->groupBox1->TabStop = false;
		this->groupBox1->Text = L"I'm a cat!";
	}
}

Open in new window


I am able to create and assign an array of variables using this class like such:

array<CatClass ^> ^ Cats;

Open in new window


And inside the Constructor, I initialiase the memory like so:

Cats = gcnew array<CatClass ^>(2);

Open in new window


Using this array is easy, by simply allocating memory for each element and then using it, like this:

				Cats[0] = (gcnew CatClass);
				Cats[0]->AddCat(this->panel1);
				Cats[1] = (gcnew CatClass);
				Cats[1]->AddCat(this->panel1);

Open in new window


The problem is that we all know that Arrays are evil as they cannot be increased on the fly - and the recommended solution of course is to use vectors.

How would I go about creating a vector of this reference class and using it?  I've tried all sorts of combinations of stuff, but I get various errors - as follows:

std::vector<CatClass>

Open in new window

IntelliSense: a using-declaration or access declaration cannot appear in a managed class

std::vector<CatClass^> CatVector;

Open in new window

IntelliSense: a member of a managed class cannot be of a non-managed class type

std::vector<CatClass> & CatVector;

Open in new window

error C2758: 'GuiAppTest01::MainForm::CatVector' : must be initialized in constructor base/member initializer list

All of the searches I've done have less complex variable types exampled in vectors, so I need to ask the experts.  Using Visual Studio 2012 Express
LVL 18
LesterClaytonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
the equivalent to a std::vector in managed c++ is a List. see

https://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

Sara

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LesterClaytonAuthor Commented:
Thank you :)  You have helped me a great deal.  This is what I've got now:

	
		List<CatClass^> ^CatList;
		CatList = gcnew List<CatClass ^>;    // Inside the Constructor

		CatClass ^cat;                       // Declare a new variable
		cat = (gcnew CatClass);              // Allocate memory
		cat->AddCat(this->panel1);
		CatList->Add(cat);                   // Store in list :D

Open in new window

LesterClaytonAuthor Commented:
Thanks for the helpful tip :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.