嘗試將std :: map與我自己的類用作值時發生錯誤。地圖的定義是這樣的:std ::將對象作爲值的地圖
std::map<std::string,CCrossSection> Xsects;
此行編譯罰款(?所以kindo作品)
Xsects[sectionId].m_vProfile.push_back(pt);
當我嘗試遍歷但是在地圖上:
for (std::map<std::string,CCrossSection>::iterator xs = Xsects.begin(); xs < Xsects.end(); xs++) {
it->second.SaveFile(f);
}
它給了我類似的多重錯誤:
error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'std::_Tree<_Traits>::iterator'
with
[
_Traits=std::_Tmap_traits<std::string,CCrossSection,std::less<std::string>,std::allocator<std::pair<const std::string,CCrossSection>>,false>
]
c:\program files\microsoft visual studio 9.0\vc\include\xtree(1466) : see declaration of 'std::operator <'
我認爲這是一個少運算符的問題,我將它添加到我的類CCrossSection的定義中,但它沒有改變一件事。後來我讀到,映射的關鍵字必須少運算符定義,我認爲std :: string有。任何想法爲什麼會發生?
乾杯 託梅克
不知道,但我想這是因爲你在做XS
Vincent
2013-04-29 07:41:42
基於Vincent的回答,我看了一下http://www.cplusplus.com/reference/iterator/iterator/ 運算符'<'沒有爲Iterator基類定義,但運算符'!='是。所以文森特是正確的。 – Jimbo 2013-04-29 07:43:18