G
Greg Buchholz
I'm wondering if anyone has advice for figuring out error messages
produced by g++. The programs below works fine, until I uncomment out
the two "transform" lines. Then it points me to line 24 (where the
second "bind1st" is) and results in an error message complaining about
no match for 'operator=' and/or problems with 'back_insert_iterator'
(see the entire error message reproduced below). Do I need a cast
somewhere to keep the type-checker happy? Is it a template problem?
Since I'm working with standard containers, I can't imagine that
there's no assignment operator defined. Is there a subtle mistake I've
made, or am I doing something obviously wrong? In addition to figuring
out this particular error, I'd also appreciate general strategies for
figuring out compiler messages produces by g++. Do commercial products
do a better job in the error message department?
Thanks,
Greg Buchholz
#include <list>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <functional>
using namespace std;
list<string> aux(list<string> ps, string n);
int main()
{
list<string> f, out;
f.push_back("foo");
f.push_back("bar");
f.push_back("baz");
list<string> g = bind1st(ptr_fun(*aux),f)("TEST");
//transform(f.begin(),f.end(),back_inserter(out),
// bind1st(ptr_fun(aux),f));
copy(g.begin(),g.end(),ostream_iterator<string>(cout, " "));
cout << endl;
return 0;
}
list<string> aux(list<string> ps, string n)
{
list<string> out;
transform(ps.begin(),ps.end(),back_inserter(out),
bind1st(plus<string>(),n));
return out;
}
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:
In function `_OutputIterator std::transform(_InputIterator,
_InputIterator, _OutputIterator, _UnaryOperation) [with _InputIterator
=
std::_List_iterator<std::string>, _OutputIterator =
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >, _UnaryOperation =
std::binder1st<std:ointer_to_binary_function<std::list<std::string,
std::allocator<std::string> >, std::string, std::list<std::string,
std::allocator<std::string> > > >]': test3.cpp:24: instantiated from
here
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:789:
error: no match for 'operator=' in
'(&__result)->std::back_insert_iterator<_Container>:perator* [with
_Container = std::list<std::string, std::allocator<std::string> >]() =
std::binder1st<_Operation>:perator()(typename
_Operation::second_argument_type&) const [with _Operation =
std:ointer_to_binary_function<std::list<std::string,
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h:363:
note: candidates are: std::back_insert_iterator<_Container>&
std::back_insert_iterator<_Container>:perator=(typename
_Container::const_reference) [with _Container = std::list<std::string,
std::allocator<std::string> >]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h:338:
note: std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >&
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >:perator=(const
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >&)
produced by g++. The programs below works fine, until I uncomment out
the two "transform" lines. Then it points me to line 24 (where the
second "bind1st" is) and results in an error message complaining about
no match for 'operator=' and/or problems with 'back_insert_iterator'
(see the entire error message reproduced below). Do I need a cast
somewhere to keep the type-checker happy? Is it a template problem?
Since I'm working with standard containers, I can't imagine that
there's no assignment operator defined. Is there a subtle mistake I've
made, or am I doing something obviously wrong? In addition to figuring
out this particular error, I'd also appreciate general strategies for
figuring out compiler messages produces by g++. Do commercial products
do a better job in the error message department?
Thanks,
Greg Buchholz
#include <list>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <functional>
using namespace std;
list<string> aux(list<string> ps, string n);
int main()
{
list<string> f, out;
f.push_back("foo");
f.push_back("bar");
f.push_back("baz");
list<string> g = bind1st(ptr_fun(*aux),f)("TEST");
//transform(f.begin(),f.end(),back_inserter(out),
// bind1st(ptr_fun(aux),f));
copy(g.begin(),g.end(),ostream_iterator<string>(cout, " "));
cout << endl;
return 0;
}
list<string> aux(list<string> ps, string n)
{
list<string> out;
transform(ps.begin(),ps.end(),back_inserter(out),
bind1st(plus<string>(),n));
return out;
}
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:
In function `_OutputIterator std::transform(_InputIterator,
_InputIterator, _OutputIterator, _UnaryOperation) [with _InputIterator
=
std::_List_iterator<std::string>, _OutputIterator =
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >, _UnaryOperation =
std::binder1st<std:ointer_to_binary_function<std::list<std::string,
std::allocator<std::string> >, std::string, std::list<std::string,
std::allocator<std::string> > > >]': test3.cpp:24: instantiated from
here
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:789:
error: no match for 'operator=' in
'(&__result)->std::back_insert_iterator<_Container>:perator* [with
_Container = std::list<std::string, std::allocator<std::string> >]() =
std::binder1st<_Operation>:perator()(typename
_Operation::second_argument_type&) const [with _Operation =
std:ointer_to_binary_function<std::list<std::string,
[with _Tp = std::string]())))'](((std::string&)(+(&__first)->std::_List_iterator<_Tp>:perator*
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h:363:
note: candidates are: std::back_insert_iterator<_Container>&
std::back_insert_iterator<_Container>:perator=(typename
_Container::const_reference) [with _Container = std::list<std::string,
std::allocator<std::string> >]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h:338:
note: std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >&
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >:perator=(const
std::back_insert_iterator<std::list<std::string,
std::allocator<std::string> > >&)