I’m trying to create a template function that takes a vector argument of any type T (primitive for now) and prints out its contents:
template<class T>
void displayContents(const vector<T>& data)
{
vector<T>::const_iterator i;
i=data.begin();
for( ; i!=data.end(); i++){
cout<<*i<endl;
}
}
The error message is:
In function ‘void displayContents(const std::vector >&)’:
error: expected ‘;’ before ‘i’ |
error:’i’ was not declared in this scope
=== Build finished: 2 errors, 0 warnings ===
Am I overlooking a syntax error?
Try the following:
As pointed out by Björn in the comment already, it is needed because is a dependent name of the template.