It is to my understanding to overload the output operator (<<) you must declare the function as standalone - OK.
And also if you want to access the private data you need to make it a "friend" of the class - OK.
But when I compile, I get a undeclared identifier error.. Any help would be appreciated.
Friend declaration in my .h file under public:
Stand-alone function (end and list are private data members):Code:friend ostream& operator<<(ostream&, GList);
Output errors:Code:ostream& operator<<(ostream& out, GList list) { for(int i = 0; i < end; i++) { out << list[i]; } return out; }
error C2065: 'end' : undeclared identifier
error C2676: binary '[' : 'GList' does not define this operator or a conversion to a type acceptable to the predefined operator
Thanks in advance..



LinkBack URL
About LinkBacks


