我有以下代码行和编译错误。应该是我对模板函数,或者c++泛型,或者其他什么的理解错误。预先感谢您指出这一点。
\n\n#include <iostream>\n#include <vector>\n\nusing namespace std;\n\ntemplate <typename T>\nT* find(vector<T> &vec, T value)\n{\n vector<T>::iterator first = vec.begin();\n vector<T>::iterator last = vec.end();\n for(; first != last; first ++)\n if(*first == value)\n return first;\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n控制台中的编译错误
\n\ndebug.cpp: In function \xe2\x80\x98T* find(std::vector<T, std::allocator<_CharT> >&, T)\xe2\x80\x99:\ndebug.cpp:9: error: expected `;' before \xe2\x80\x98first\xe2\x80\x99\ndebug.cpp:10: error: expected `;' before \xe2\x80\x98last\xe2\x80\x99\ndebug.cpp:11: error: \xe2\x80\x98first\xe2\x80\x99 was not declared in this scope\ndebug.cpp:11: error: \xe2\x80\x98last\xe2\x80\x99 was not declared in this scope\nRun Code Online (Sandbox Code Playgroud)\n