- 论坛徽章:
- 0
|
- #include<unordered_set>
- using namespace std;
- struct node{
- size_t value;
- node* next;
- node():value(-1),next(NULL){}
- };
- struct myhash{
- size_t operator()(const node& n)const{
- return (size_t)n.value;
- }
- };
- size_t h(const node& n){
- return (size_t)n.value;
- }
- int main(){
- unordered_set<node, myhash> s1;
- unordered_set<node, h> s2;
- unordered_set<node, [](const node& e){return n.value;}> s;
- return 0;
- }
复制代码
编译main函数,第二行和第三行有编译错误。
- ||=== Build: Release in my (compiler: GNU GCC Compiler) ===|
- C:\Users\a\Documents\my\main.cpp||In function 'int main()':|
- C:\Users\a\Documents\my\main.cpp|18|error: type/value mismatch at argument 2 in template parameter list for 'template<class _Value, class _Hash, class _Pred, class _Alloc> class std::unordered_set'|
- C:\Users\a\Documents\my\main.cpp|18|note: expected a type, got 'h'|
- C:\Users\a\Documents\my\main.cpp|19|error: lambda-expression in template-argument|
- C:\Users\a\Documents\my\main.cpp|19|error: template argument 2 is invalid|
- C:\Users\a\Documents\my\main.cpp|18|warning: unused variable 's2' [-Wunused-variable]|
- C:\Users\a\Documents\my\main.cpp|19|warning: unused variable 's' [-Wunused-variable]|
- ||=== Build failed: 3 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
复制代码
这个是unordered_set的限制,还是我的用法有问题呢?
谢谢
|
|