Hey guys,
I got this code, and I can't get it to compile, no clue what I'm doing wrong.
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
template <class T>
void kill_dupes(vector<T> &x){
vector<T> y;
for(vector<T>::iterator it = x.begin(); it != x.end(); it++){
if(find(x.begin(), x.end(), *it) == x.end()){
y.push_back(*it);
}
}
x = y;
return;
}
int main(){
return 0;
}
GCC MinGW says:
main.cpp||In function `void kill_dupes(std::vector<T, std::allocator<_CharT> >&)':|
main.cpp|12|error: expected `;' before "it"|
main.cpp|12|error: `it' was not declared in this scope|
main.cpp||In function `void kill_dupes(std::vector<T, std::allocator<_CharT> >&) [with T = int]':|
main.cpp|31|instantiated from here|
main.cpp|12|error: dependent-name ` std::vector<T,std::allocator<_CharT> >::iterator' is parsed as a non-type, but instantiation yields a type|
main.cpp|12|note: say `typename std::vector<T,std::allocator<_CharT> >::iterator' if a type is meant|
||=== Build finished: 3 errors, 0 warnings ===|
Of course it wasn't declared, I'm trying to declare it (no pun intended).
kill_dupes is called with a vector<int>.
Thanks in advance,
Edit:
This works as expected:
void kill_dupes(vector<int> &x){
vector<int> y;
for(vector<int>::iterator it = x.begin(); it != x.end(); it++){
if(find(x.begin(), x.end(), *it) == x.end()){
y.push_back(*it);
}
}
x = y;
return;
}
What's the difference? *-)