誰能請解釋爲什麼下面將編譯爲什麼在使用std :: max和C++/CLI時不編譯?
int a = aAssignments[i]->Count;
int b = fInstanceData->NumRequiredEmpsPerJob[i];
fInstanceData->NumSlotsPerJob[i] = max(a,b);
但
fInstanceData->NumSlotsPerJob[i] = max((int)(aAssignments[i]->Count), (int)(fInstanceData->NumRequiredEmpsPerJob[i])); //why on earth does this not work?
不會?它提供錯誤是error C2665: 'std::max' : none of the 7 overloads could convert all the argument types
可變aAssigmments
是array<List<int>^>^
類型和fInstanceData->NumRequiredEmpsPerJob
是array<int>^
爲std::max
手冊說,它以引用的取值類型的,因此它明顯地含蓄地在第一個例子中這樣做,那麼爲什麼編譯器不能對count屬性返回的整數值做同樣的事情?就像第二個例子一樣?我可以明確地獲得對int的引用嗎?
它甚至如何編譯'Count'屬性,數組具有'Length'屬性。 – leppie 2010-10-21 10:40:30
@leppie這是一個列表數組,我將數組索引到'i'並計算該列表的元素。 – 2010-10-21 11:00:05
啊正確:)我錯過了。 – leppie 2010-10-21 11:05:42