1

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.

Community
  • 1
  • 1
dandar
  • 175
  • 1
  • 9

1 Answers1

1

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!

Community
  • 1
  • 1
Matt Smith
  • 17,026
  • 7
  • 53
  • 103
  • Thanks very much Matt for your very quick reply. I really appreciate this. The workaround you suggest was devised by you, so I guess you are a good person to get advice from! I will take a look at your workaround tomorrow and see if I can understand it and get it working for my situation. – dandar Mar 13 '12 at 18:29