R
Rares Vernica
Hi,
I am trying to write a template that will take any type of vector and
output it in a certain way. Here is my code:
#include <ostream>
#include <vector>
#include <iterator>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, const vector<T> v)
{
out << '[';
for(vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
out << ", ";
}
out << *it;
}
out << ']';
return out;
}
I get the following error:
output.h: In function `std:stream& operator<<(std:stream&,
std::vector<T, std::allocator<_CharT> >)':
output.h:22: error: expected `;' before "it"
output.h:22: error: `it' undeclared (first use this function)
output.h:22: error: (Each undeclared identifier is reported only once
for each function it appears in.)
make: *** [output.o]
Do you have any idea what the problem might me?
Thank you very much,
Ray
I am trying to write a template that will take any type of vector and
output it in a certain way. Here is my code:
#include <ostream>
#include <vector>
#include <iterator>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, const vector<T> v)
{
out << '[';
for(vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
out << ", ";
}
out << *it;
}
out << ']';
return out;
}
I get the following error:
output.h: In function `std:stream& operator<<(std:stream&,
std::vector<T, std::allocator<_CharT> >)':
output.h:22: error: expected `;' before "it"
output.h:22: error: `it' undeclared (first use this function)
output.h:22: error: (Each undeclared identifier is reported only once
for each function it appears in.)
make: *** [output.o]
Do you have any idea what the problem might me?
Thank you very much,
Ray