自分のクラスを値として std::map を使用しようとするとエラーが発生します。マップの定義は次のとおりです。
std::map<std::string,CCrossSection> Xsects;
この行は正常にコンパイルされます(つまり、動作しますか?)
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 は持っていると思います。なぜそれが起こるのですか?
乾杯トメック