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 your gcroot
first.
using namespace System::Collections::ObjectModel;
Collection<BModel::Device ^> ^d = Devices;
d[0] //... this should work
The above represents an implicit cast (this is why you cannot use auto
). You can use static_cast
if you need one-liner:
static_cast<Collection<BModel::Device ^> ^>(Devices)[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With