- 論壇徽章:
- 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;
復(fù)制代碼- 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()]);
復(fù)制代碼 編譯的時候提示:
1> error C2780: “void std::sort(_RanIt,_RanIt,_Pr)”: 應(yīng)輸入 3 個參數(shù),卻提供了 2 個
1> e:\program files\microsoft visual studio 9.0\vc\include\algorithm(3273) : 參見“std::sort”的聲明
1> error C2782: “void std::sort(_RanIt,_RanIt)”: 模板 參數(shù)“_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是沒有任何問題的.
大家?guī)兔纯窗?! |
|