The second sample in this MSDN article demonstrates how to convert an STL/CLR map<> to a .NET IDictionary<>. I tried to transpose this pattern to a conversion from a vector<> to an array<>, but this code fails to compile:
The last line before the return statement gives me an error C2440, telling me that a 'cliext::vector<_Value_t> ^' can't be converted into a 'cli::array<Type> ^'.Code:#include <cliext/adapter> #include <cliext/vector> // ... using namespace cliext; // ... // Return an array of moving holidays in a specific year array<DateTime> ^Holidays::MovingHolidays(int nYear) { vector<DateTime> ^vctHolidays=gcnew vector<DateTime>; DateTime datEasterSunday=EasterSunday(nYear); // Just a few for a first test: vctHolidays->push_back(datEasterSunday+TimeSpan(-2,0,0,0)); // Karfreitag vctHolidays->push_back(datEasterSunday); // Ostersonntag (of course... <g>) vctHolidays->push_back(datEasterSunday+TimeSpan(1,0,0,0)); // Ostermontag array<DateTime> ^adatHolidays=vctHolidays; return adatHolidays; }
I only had to go that detour at all because I didn't find a method like push_back or add for the CLI array
There was, BTW, something that made me wonder in the MSDN sample code: It declares a stand-alone variable of type System::Collections::Generic::IDictionary<float, int>. I always were of the strong belief that these ISomethings could only be implemented as part of a "hosting" class.
TIA for any advice about that!![]()



Reply With Quote

Bookmarks