c++ - C++模板参数函数
问题描述
这里是 C++ 初学者!:-) 我试图通过模仿 STL 算法中的函数来编写函数。
template<class InputIterator>
InputIterator findNegativeMax(InputIterator, InputIterator);
以上是some.hpp
文件中的声明。下面是函数的定义findNegativeMax()
。
template<class InputIterator>
InputIterator findNegativeMax(InputIterator first, InputIterator last){
Iterator position = nullptr;
while(first <= last){
/*some logic*/
}
return position;
}
如前所述,我试图模仿诸如 max_element implementation之类的 STL 代码。但是当我编译看起来像的测试代码时
int main(){
std::vector<int> vec = {1,2,3,44,4,-5,-5,-2};
auto it = algo::findNegativeMax(vec.begin(),vec.end());
std::cout<<"position::"<<*it<<std::endl;
return 0;
}
.但是当使用所有必要的对象和属性进行编译时,我收到以下错误
/tmp/ccma7n9Q.o:在函数main':
testAlgo.cpp:(.text+0x87): undefined reference to
__gnu_cxx::__normal_iterator >> algo::findNegativeMax<__gnu_cxx::__normal_iterator >>>(__gnu_cxx::__normal_iterator >>, __gnu_cxx::__normal_iterator >>)' collect2:错误:ld 返回 1退出状态
如果问题无论如何是错误的,请原谅。
先感谢您。
解决方案
推荐阅读
- python - OpenCL 将输入映射到输出
- reactjs - 如何将 ag-grid-react 包装到组件中?
- javascript - 如何从 jquery 范围滑块中获取值
- amazon-ec2 - 在 Jenkins 中使用 AWS 命令获取 EC2 实例的 CPU 利用率的最佳方法是什么
- javascript - Puppeteer 尝试加载延迟加载的图像失败
- security - 如果无法解析属性,ABAC PIP 应该怎么做?
- java - 如何将只读属性应用于 C: 目录中的所有 .docx 和 .pptx 文件?使用 java
- php - 如何排列以下数组?
- c# - 从单词列表中将多个单词替换为字符串中的其他单词
- sql - 插入中的VBA SQL错误