注册 登录
编程论坛 C++教室

函数模板问题 编译错误

stop1204 发布于 2017-12-24 07:52, 1484 次点击
程序代码:

//
//实例
template<typename T1, typename T2>
T1 findValue (T1 beg, T1 vend, T2 ival) {
    return beg;
}

//声明
template<typename T1, typename T2> T1 findValue (T1 beg, T1 vend, T2 ival);

//运行
findValue (vec.begin(), vec.end(), 5);

编译错误:
undefined reference to `__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > > findValue<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int>(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int)'|
简化一下就是
undefined reference to `T findValue<T, int>(T, T, int)'|


给我找一下什么情况..  找不出来   

[此贴子已经被作者于2017-12-24 07:53编辑过]

1 回复
#2
stop12042017-12-24 10:19
已经知道了.
模板需要直接写在头文件
1