1
votes

I have been trying to find a way to pass a std::vector from native C++ code into a static method in a C++/CLI managed class. I am new to C++ (non-managed) and so it is not surprising I have had no luck with this. What I would like is some pointers as to how a std:vector (of any type, but preferably double or int) can be converted to managed C++/CLI arrays and/or C# arrays. Perhaps this cannot be done since I only see examples to do the opposite (i.e. C# to native C++), for example see "convert System::array to std::vector". Below I summarise my abortive attempts.

I can pass a double vector such as

   vector<vector<double> > dblvec

into a method defined in a native C++ class (where the class is in a C++/CLI project), but not into a method defined in a ref class (also in a C++/CLI project). The comiler complains that the method (in the ref class) does not exist (candidate function not accessible). I think this is something to do with vector > being foced to be a private variable (see for example C++ CLI error C3767: candidate function(s) not accessible).

Any help would be greatly appreciated.

1

1 Answers

1
votes

Yes, you are essentially correct about the cause (native types are not public outside the assembly). And you can't easily fix it since templated types cannot be made public (even by using the make_public pragma).

You'll want to read the following for a workaround: Best workaround for compiler error C2158: make_public does not support native template types

Good luck!