views:

174

answers:

1

I'm trying to create a vector of System::String ^, I tried using the straight up STL vector, but vector<String ^> my_vector gives a C4439 error (function needs to have a __clrcall calling convention.

So, I added __clrcall to my function prototype, and it still complained about my declaration of vector<String ^>.

I'm also reading through the MSDN pages on the VC++ library, but I haven't found what I need yet, anybody out there know what I need? Thanks.

+1  A: 

You're trying to put a managed object (the String) under control of an unmanaged object, but the managed heap can move things around in memory and that's a problem for the vector. Basically, you can't stick managed objects into STL containers, though it may be allowed in managed C++ with pinning (I haven't tried that) and getting the actual char * out of it.

However, .NET provides similar classes such as the List<T> generic that will do the same thing for you, but in managed code. If you're on an older version of .NET, look at something like ArrayList, Stack, or Queue.

John Cavan
An ArrayList was almost exactly what I was hoping for, but I couldn't find it for some reason. Thanks.
thepocketwade
No prob. If you can use the generic 'List<T>' instead, that's a better option because you'll get type checking that you won't get with an ArrayList.
John Cavan