这里定义了一个模版函数,功能同STL里的copy函数:
#include <vector>
#include <list>
#include <iostream>
template <typename Iter1, typename Iter2>
Iter2 copy(Iter1 f1, Iter1 e1, Iter2 f2)
{
for (f1; f1 != e1; ++f1, ++f2)
{
*f1 = *f2;
}
return f2;
}
int main()
{
int arr[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> vec{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
copy(arr, arr + 10, vec.begin());
return 0;
}
编译时报了call of overloaded 'copy(int [10], int*, std::vector<int>::iterator)' is ambiguous
错误。
c:\Source\drill.cpp: In function 'int main()':
c:\Source\drill.cpp:27:36: error: call of overloaded 'copy(int [10], int*, std::vector<int