c++ 模板错误

来源:百度知道 编辑:UC知道 时间:2024/05/29 16:13:41
题目:
定义一个类模板 接受未知类型的一对迭代器 在这对迭代器中找出出现最多的值

我的代码:
#include <iostream>
#include <string>
#include <map>
#include <set>
using namespace std;

template <typename Type>
Type find_top(Type *beg,Type *end)
{
map< Type , set<int> > body;
while(beg != end)
body[*beg++].insert(1);

return body.begin() -> first;
}

int main()
{
string s = "uxdjfsd";
string::iterator sBeg = s.begin();
string::iterator sEnd = s.end();
find_top(sBeg,sEnd);
getchar();
return 0;
}

如果用
int main()
{
int a[10];
int *aB = a;
int *aE = a + 10;
find_top(aB,aE);
getchar();
return 0;
}
则是正确的
我知道iterator 和 int*的 类型是不一样的 但是要怎么改
汗 我用的是dev-c++

这个程序编译链接都通过了,并没有错啊.我用的是VC6.0
int main()
{
string s = "uxdjfsd";
string::iterator sBeg = s.begin();
string::iterator sEnd = s.end();
cout<<find_top(sBeg,sEnd)<<endl; //在这里可以输出结果.
getchar();
return 0;
}

应该是正确的哈!我还是使用 6.0的版本