This question already has an answer here:
A C++ beginner here! :-) I was trying to write a function by mimicking those in STL algorithm.
template<class InputIterator>
InputIterator findNegativeMax(InputIterator, InputIterator);
The above is the declaration in some.hpp
file. And below is the definition of the function findNegativeMax()
.
template<class InputIterator>
InputIterator findNegativeMax(InputIterator first, InputIterator last){
Iterator position = nullptr;
while(first <= last){
/*some logic*/
}
return position;
}
As stated earlier I tried to mimic the STL code like max_element implementation. but when I compile the test code which looks like
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;
}
.But when compiling with all necessary objects and attributes included I'm getting the following error
/tmp/ccma7n9Q.o: In function 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: error: ld returned 1 exit status
Please pardon if the question is in anyway misformed.
Thank you in Advance.
Aucun commentaire:
Enregistrer un commentaire