This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: could list's object be used with (for_each)?
On Thu, Jul 7, 2011 at 15:44, eric <cneric12lin0@gmail.com> wrote:
> 4-8.cpp:25:44: error: no matching function for call to
> âfor_each(std::list<std::basic_string<char> >::iterator,
> std::list<std::basic_string<char> >::iterator, <unresolved overloaded
> function type>)â
>
This is due to the author forgetting that C++ headers are allowed to
include other headers. The "write" function ends up overloaded with
another write, and for_each doesn't know which one you mean.
You can fix this by renaming the write function (perhaps to "my_write"
or similar), or by applying a cast operator to pick the overload you
want (something like "for_each(lst.begin( ), lst.end( ),
(void(*)(string const &))write);").
~ Scott
P.S. For "why doesn't this compile?" questions, please refer to a
general C++ list/channel before asking here, as it's rarely something
GCC specific.