overloaded ostream and binary arithmetic operators-template

I am having difficulty with my template version of an overloaded ostream and binary arithmetic operators. I am attempting to have strings added to an array and then print out the array but the compiler doesn't like something about my declarations of these operators. Any help would be appreciated.

code calling the operators:
1
2
3
4
5
6
  Array<string> sarr

cout<<"Array class as String : "<<endl;
    for (int i = 0; i < 20; i++)
	sarr += "array";
    cout << sarr << endl << endl;


Here are the operators declared
1
2
3
4
5
6
7
8
template <typename T>
std::ostream &operator <<(std::ostream &os, const Array<T> &array);
template <typename T>
class Array {
	friend std::ostream &operator << <>(std::ostream &os, const Array<T> &array);
public:
Array &operator +=(T val);


Definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template <typename T>
ostream &operator << (ostream &os, const Array<T> &array) {
	os << "{";
	for (int i = 0; i < array.size; i++)
		os << array.arr[i] << (i < array.size-1 ? ", " : "");
	os << "}";
	return os;

template <typename T>
Array<T> &Array<T>::operator +=(T val) {
	checkCapacity();
	arr[size] = val;
	size++;
	return *this;
}
Last edited on
Topic archived. No new replies allowed.