0
我有一個名爲mySize
的成員變量,我想計算與地圖大小的差值,如myMap
。在申報mySize
時應使用哪種類型?我現在在使用uint32_t。 例如, 在myClass.h
:如何聲明將使用map.size()計算的int類型
static uint32_t getDifference(std::map<string, int> myMap);
static uint32_t mySize_;
在myClass.cpp
:
uint32_t getDifference(std::map<string, int> myMap){
return std::abs(mySize_ - myMap.size());
}
更新:在上面的代碼臨界錯誤。 std::abs
不能用於uint32_t
。但這與問題無關。我應該使用std::size_t
而不是uint32_t
。
這是'size_t'的類型。 –
你複製整個地圖只是爲了問它的大小?這很原始 – Slava
爲什麼你不檢查參考:['std :: map'](http://en.cppreference.com/w/cpp/container/map),['std :: map :: size ()'](http://en.cppreference.com/w/cpp/container/map/size)。或者,你可以查看源代碼 – Drop