In C++/CLI it is not possible to put pointers to native C++ classes in managed .NET generic collections, e.g.
class A {
public:
int x;
};
public ref class B {
public:
B()
{
A* a = GetPointerFromSomewhere();
a->x = 5;
list.Add(a);
}
private:
List<A*> listOfA; // <-- compiler error (T must be value type or handle)
}
is not allowed. I could of course use std::vector<A*> list; but then I could only make list a member of a managed class by using a pointer and it feels unnatural to use pointers to STL containers.
What is a good way to store native C++ pointers in .NET generics? (I'm not interesting in resource management here; the object the pointer points to is managed elsewhere)