我有一个函数,其中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