- 论坛徽章:
- 0
|
如下的代码:
- // The ID class is used for team scoring. It holds each player's name
- // and score.
- class ID
- {
- public:
- string Name;
- int Score;
- ID() : Name(""), Score(0) {}
- ID(string NewName, int NewScore) : Name(NewName), Score(NewScore) {}
- };
- // In this example, an ID is equivalent only if both name and score match.
- bool operator==(const ID& x, const ID& y)
- {
- return (x.Name == y.Name) && (x.Score == y.Score);
- }
- // IDs will be sorted by Score, not by Name.
- bool operator<(const ID& x, const ID& y)
- {
- return x.Score < y.Score;
- }
- // Define a template class for a vector of IDs.
- typedef vector<ID> NAMEVECTOR;
复制代码- NAMEVECTOR Vector1;
- Vector1.push_back(ID("Karen Palmer", 2));
- Vector1.push_back(ID("Ada Campbell", 1));
- // Sort the vector of players by score.
- // !!!!! something going wrong here.
- sort(Vector1.begin(), &Vector1[Vector1.size()]);
复制代码 编译的时候提示:
1> error C2780: “void std::sort(_RanIt,_RanIt,_Pr)”: 应输入 3 个参数,却提供了 2 个
1> e:\program files\microsoft visual studio 9.0\vc\include\algorithm(3273) : 参见“std::sort”的声明
1> error C2782: “void std::sort(_RanIt,_RanIt)”: 模板 参数“_RanIt”不明确
1> e:\program files\microsoft visual studio 9.0\vc\include\algorithm(3110) : 参见“std::sort”的声明
1> 可能是“ID”
1> 或 “std::_Vector_iterator<_Ty,_Alloc>”
1> with
1> [
1> _Ty=ID,
1> _Alloc=std::allocator<ID>
1> ]
不知道啥意思呢.... 貌似是说不能匹配的,但这些代码在vc6是没有任何问题的.
大家帮忙看看啊 ! |
|