struct ch{ //选课
int st_id; // 学号
int sb_id; // 课程号
};
map<ch, int> cho;
bool choose::check(ch f)
{
int x = cho[f];
return x != 0;
}
也不知道为什么,总之好像只要直接用一个结构体的变量作为键值而不是手写的{a, b}
这个样子的,就会报一堆奇怪的错误
52 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\bits\stdc++.h from D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32/bits/stdc++.h
2 C:\Users\30504\Desktop\新建文件夹 (2)\main.cpp from main.cpp
D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_function.h In instantiation of 'bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = ch]':
498 31 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_map.h required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = ch; _Tp = int; _Compare = std::less<ch>; _Alloc = std::allocator<std::pair<const ch, int> >;
std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = ch]'
371 20 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_function.h [Error] no match for 'operator<' (operand types are 'const ch' and 'const ch')
371 20 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_function.h [Note] candidates are:
371 20 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_function.h [Note] candidates are:
58 0 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\regex In file included from D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/regex
108 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\bits\stdc++.h from D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32/bits/stdc++.h
1428 5 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\regex.h [Note] template<class _Bi_iter> bool std::operator<(const std::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)
1428 5 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\regex.h [Note] template argument deduction/substitution failed:
48 0 D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\string In file included from D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/string
......
然后我查了一下原因,必须得加个排序才行
如下
struct ch{ //选课
int st_id; // 学号
int sb_id; // 课程号
bool operator < (const ch &a)const
{
if (st_id == a.st_id) return sb_id < a.sb_id;
else return st_id < a.st_id;
}
};
这样就好了