【发布时间】:2014-05-12 09:11:30
【问题描述】:
我是 C++ 新手。我尝试在 clang 3.4 中使用“-std=c++11 -stdlib=libc++”标志编译一个非常简单的 std::map progeam,但出现了我不理解的错误。
#include<map>
#include<string>
template<typename KeyType>
struct ReverseSort {
bool operator() (const KeyType& key1, const KeyType& key2) {
return (key1 > key2);
}
};
int main() {
using namespace std;
map<int, string> mapIntToString1;
map<int, string, ReverseSort<int> > mapIntToString4(mapIntToString1.cbegin(), mapIntToString1.cend());
return 0;
}
错误是:
map:457:17: error: no matching function for call to object of type 'const ReverseSort<int>'
我知道错误来自 main() 中的第 3 行,只是不明白为什么。 相同的程序在带有“-std=c++11”标志的 g++ 4.8.2 中很好,我相信在 VC2010 中也很好。
谢谢。
【问题讨论】:
-
为什么不直接使用
std::greater<int>?! -
究竟是什么VC2010?
-
@Jagannath 你的评论太离谱了。这是一个完全有效的问题。