Hi, LeafyCircuits here (•‿•)
After recently learning about templates, I began an experiment, but so far, that isn't turning out well.
I'm trying to templatize a custom function that overloads the << operator.
Here's the code:
template <typename T>
ostream& operator << (ostream &out, vector<T> &vec)
out << *itr; //edit: was 'cout', now 'out'
I want to be able to output the contents of any vector by simply calling
cout << somevector << endl;
However, when I try to compile, I get the following errors:
Line 4: expected `;' before "itr"
Line 5: `itr' undeclared (first use this function)
But, I know for a fact that I have correct syntax on this line:
So here's my question: Can you templatize an operator this way? If not, can you templatize operators in general?
I'm terribly new to the forums, so constructive criticism is greatly appreciated. Thank you for reading my plight. (•‿•)