0

I have a problem with to create std::vector with String^ objects:

std::vector<String^> vSometing;

It prompt an error:

'&&': cannot use this indirection on type 'System::String ^'

So how to do list of String^ objects?

Piotr Wasilewicz
  • 1,751
  • 2
  • 15
  • 26
  • *Some* basic understanding of how garbage collection works is pretty crucial when you try to write interop code. Although the compiler will often rap your knuckles when you get it wrong. It can only work when it can find object roots back, like those System::String references. Can't work when you store them in an std::vector, the GC has no clue what that type looks like so can't look in the right place for the object reference. You'll have to use an `std::vector` to keep it all native or a `List^` to keep it all managed. – Hans Passant Aug 14 '16 at 11:26

1 Answers1

0

You could use the STL/CLR library if you really prefer using STL collections. One solution is List. Vector uses new to allocate it's objects, but you can't allocate System::String^.

Soo use List<String^> or convert System::String^ to std::string. How to convert, look this topic.

Community
  • 1
  • 1
Nejc Galof
  • 2,538
  • 3
  • 31
  • 70
  • Please read [this article](http://www.codeproject.com/Articles/24206/A-look-at-STL-CLR-performance-for-linear-container) before you consider recommending STL/CLR. – Hans Passant Aug 14 '16 at 11:27