The main problem here is that you are trying to mix C++/CLI objects and C++ containers.
In your case, you don't want to use a std::vector
or std::list
here. Instead, you should declare Daten
as a ref class
and use a List
to store the buttons.
using namespace System.Collections.Generic; //For Generic List
public ref class Daten
{
public:
Daten();
void addButton(MyButton^ pBtn);
MyButton^ getButton(int pIdx);
private:
List<MyButton^>^ myButton;
};
I don't think you want the list to be static without the member functions being static (either all or none), so I removed that. It also looks like it should be using MyButton
everywhere.
Reasons why you would use a std::vector
in C++/CLI code:
If you have existing (pure) C++ code to process information, you may want to build a vector of objects, but in this case, you would build it with pure C++ data and not with .Net classes or objects. You might also call C++ code that returns data in a std::vector
. In this case, you might then translate/marshal the data into .Net collections and object to work with in C++/CLI or to send to .Net classes built with C#.
Note:
If you really want to use std::vector
and did not intend on starting a C++/CLI project, you need to start over and pick a different template for the project (MFC or Win32 are two options for this and the UI will not be WinForms and you will not have access to .Net objects or classes).