operator overloading

I am trying to overload the << operator. Why isn't it working?

1
2
3
4
5
6
7
void operator<<(ostream& out,Array array1)
{
	for(int i=0;i<8;i++)
	{
		out<<array1.array[i];
	}
}
it must return an ostream reference (ostream&) not void
why?
To do something like this:
out_stream<<array1<<array2<<array3;
I have run the program it is right. i have done it by friend function. my code is as below let's try it......



#include<iostream>
using namespace std;

class Array
{
public:
int array[8];

friend void operator <<(ostream &, Array );
};

void operator <<(ostream& out,Array array1)
{
for(int i=0;i<8;i++)
{
out<<"\t"<<array1.array[i];
}
}



int main()
{
Array a;


cout<<"\n\t Enter 8 integers for array:";

for(int i=0; i<8; i++)
{
cin>>a.array[i];
}

cout<<"\n\t the elements of array are:";
cout<<a;
cout<<endl;

return 0;
}


okay i got it now
Topic archived. No new replies allowed.