P
Pushkar Pradhan
I'm overloading the << operator to o/p a list of structures like this:
typedef struct point {
int x;
int y;
} PARTICLE;
so that I can print out the list using:
cout << "hull: " << hull << endl;
This is how I overloaded the << operator before main():
//--- Overload output operator for list<T>
template <typename T>
ostream & operator<<(ostream & out, const list<T> & l) {
for(list<T>::iterator i = l.begin(); i != l.end(); i++)
//out << *i.x << *i.y << " ";
return out;
}
However I get this compile error:
main.cpp: In function `class ostream & operator <<<PARTICLE>(ostream &,
const list<point,allocator<point> > &)':
main.cpp:66: instantiated from here
main.cpp:18: conversion from `_List_iterator<point,const point &,const
point *>' to non-scalar type `_List_iterator<point,point &,point *>'
requested
main.cpp:66: instantiated from here
main.cpp:18: no match for `_List_iterator<point,point &,point *> & !=
_List_iterator<point,const point &,const point *>'
/usr/local/gnu/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/stl_list.h:70:
candidates are: bool _List_iterator<point,point &,point *>:perator
!=(const _List_iterator<point,point &,point *> &) const
Can anyone tell me what more do I need to do?
Pushkar Pradhan
typedef struct point {
int x;
int y;
} PARTICLE;
so that I can print out the list using:
cout << "hull: " << hull << endl;
This is how I overloaded the << operator before main():
//--- Overload output operator for list<T>
template <typename T>
ostream & operator<<(ostream & out, const list<T> & l) {
for(list<T>::iterator i = l.begin(); i != l.end(); i++)
//out << *i.x << *i.y << " ";
return out;
}
However I get this compile error:
main.cpp: In function `class ostream & operator <<<PARTICLE>(ostream &,
const list<point,allocator<point> > &)':
main.cpp:66: instantiated from here
main.cpp:18: conversion from `_List_iterator<point,const point &,const
point *>' to non-scalar type `_List_iterator<point,point &,point *>'
requested
main.cpp:66: instantiated from here
main.cpp:18: no match for `_List_iterator<point,point &,point *> & !=
_List_iterator<point,const point &,const point *>'
/usr/local/gnu/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/stl_list.h:70:
candidates are: bool _List_iterator<point,point &,point *>:perator
!=(const _List_iterator<point,point &,point *> &) const
Can anyone tell me what more do I need to do?
Pushkar Pradhan