See if this helps:
Code:
#include <iostream>
using namespace std;
class GList
{
private:
int end;
int* pArray;
public:
GList(int size, int* anArray)
{
end = size;
pArray = anArray;
}
friend ostream& operator<<(ostream&, const GList&);
};
ostream& operator<<(ostream& out, const GList& list)
{
for(int i=0; i<list.end; i++)
{
out<<list.pArray[i]<<endl;
}
return out;
}
int main()
{
int size = 3;
int arr[] = {10, 20, 30};
GList myList(size, arr);
cout<<myList;
return 0;
}
Note: you should make the GList parameter a reference to avoid having to copy the object for the function, and you should make it a const since the function doesn't need to change the GList object.