Hi I am trying to overload << operator for a simple class
Unfortunately my approach to overloading << doesn't work
The error is as following
Does anybody know how to fix it?
I'm using Ubuntu 6.10 and standard g++ compiler
Regards, Martin
(OS and comp.)
using Linux and gcc
Code:
class String
{
private:
std::list<std::string> data;
public:
//some simple functions
}
;
Unfortunately my approach to overloading << doesn't work
Code:
inline std::ostream& operator<<(std::ostream& os, const String &str)
{
std::list<std::string>::iterator idx;
idx=(str.data).begin() ;
//for(idx=str.data.begin(); idx!=str.data.end(); ++idx)
os<<*idx<<endl;
return os;
}
Code:
error: no match for ‘operator=’ in ‘idx = str->String::data. std::list<_Tp, _Alloc>::begin [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]()’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_list.h:112: note: candidates are: std::_List_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >& std::_List_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator=(const std::_List_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&)
I'm using Ubuntu 6.10 and standard g++ compiler
Regards, Martin
(OS and comp.)
using Linux and gcc