#include
#include
#include
using namespace std;
template
it _find(it t1, const it t2, const value &x)
{
while (t1 != t2)
{
if (*t1 == x)
{
cout << "found!" << endl;
return t1;
}
++t1;
}
cout << "not found!" << endl;
}
int main(void)
{
vector v1(10, 1), v2(10, 2);
_find(v1.cbegin(), v1.cend(), 1);
_find(v2.cbegin(), v2.cend(), 1);
}
虽然能出结果,但是运行完后会这样:
谢谢各位大神。
你可以在代码中设置断点,跟踪一下,看你的代码运行到出错的时候,具体是哪一行代码
int main(void) // main是这种原型么??
{
vector v1(10, 1), v2(10, 2);
_find(v1.cbegin(), v1.cend(), 1);
_find(v2.cbegin(), v2.cend(), 1);
// 没有返回值也能通过编译??
}