I’m making bridge from .NET to C++ and using Collection as a public element like this :
gcroot<System::Collections::ObjectModel::Collection<BModel::Device ^> ^> Devices;
I’m using gcroot because my c++ class is not managed (it’s MFC) but I’m having trouble with accessing it. When I am doing :
Devices[x]->devicename
I’ve got error :
Error 6 error C2676: binary ‘[‘ : ‘gcroot’ does not define this
operator or a conversion to a type acceptable to the predefined
operator
So I guess I must access collection element somehow but not with this brackets : [ ]
So how to access gcroot clr collection element ?
While the member access operator,
->is overloaded, it appears as if the subscript operator[]isn’t, unwrap yourgcrootfirst.The above represents an implicit cast (this is why you cannot use
auto). You can usestatic_castif you need one-liner: