我有一個函數,其中const std::map<std::string, Array2D<unsigned short>&>* pDataPool
是其輸入參數之一。還有函數體中的代碼片段如下:如何迭代此地圖?
std::map<std::string, Array1D<unsigned short>*> DataBuffers;
if (pDataPool != NULL)
{
for (std::map<std::string, Array2D<unsigned short>&>::iterator it = pDataPool->begin();
it != pDataPool->end(); it++) // Error
{
std::string sKeyName = it->first;
DataBuffers[sKeyName] = new Array1D<unsigned short>(2048);
}
}
編譯器輸出:
1>e:\program files\microsoft visual studio 9.0\vc\include\map(168) : error C2529: '[]' : reference to reference is illegal
1> f:\tips\tips\fy2svsdataiohandler.cpp(77) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=Array2D<unsigned short> &
1> ]
1>f:\tips\tips\fy2svsdataiohandler.cpp(77) : error C2440: 'initializing' : cannot convert from 'std::_Tree<_Traits>::const_iterator to <br/>'std::_Tree<_Traits>::iterator'
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,Array2D<unsigned short> &,std::less<std::string>,std::allocator<std::pair<const <br/> std::string,Array2D<unsigned short> &>>,false>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>Build log was saved at "file://f:\Tips\Tips\Debug\BuildLog.htm"
1>Tips - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
在代碼segement,第一行應爲:的std ::地圖<的std :: string,Array1D <無符號短> *>數據緩衝區; – GoldenLee 2011-06-14 07:19:16
對不起,我不知道如何擺脫SO中使用的特殊字符「<" and ">」。所以,我寫了一個醜陋的字符串const std :: map'<'std :: string,Array2D'''unsigned short'>'&'>'* pDataPool。它應該是const std :: map&> * pDataPool。 –
GoldenLee
2011-06-14 07:24:11
有一個標題爲「格式」的巨大面板出現在您寫問題的空間旁邊。閱讀! – 2011-06-14 07:30:18