fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <functional>
  5. using namespace std;
  6. struct Add : public binary_function<int, int, int> {
  7. int operator()(int & _Left, const int & _Right) const//LINE I
  8. { return _Left+_Right;}
  9. };
  10. void printer(int i) {
  11. cout << i << ", ";
  12. }
  13. int main() {
  14. int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
  15. vector<int> v1(mynumbers, mynumbers + 7);
  16. vector<int> v2(7);
  17. transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(), -1));//LINE II
  18. for_each(v2.rbegin(), v2.rend(), printer);
  19. return 0;
  20. }
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/5/bits/stl_function.h:1128:0,
                 from /usr/include/c++/5/string:48,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:2:
/usr/include/c++/5/backward/binders.h: In instantiation of 'typename _Operation::result_type std::binder1st<_Operation>::operator()(typename _Operation::second_argument_type&) const [with _Operation = Add; typename _Operation::result_type = int; typename _Operation::second_argument_type = int]':
/usr/include/c++/5/bits/stl_algo.h:4175:24:   required from '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _OIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _UnaryOperation = std::binder1st<Add>]'
prog.cpp:17:71:   required from here
/usr/include/c++/5/backward/binders.h:129:29: error: no match for call to '(const Add) (const first_argument_type&, std::binary_function<int, int, int>::second_argument_type&)'
       { return op(value, __x); }
                             ^
prog.cpp:7:13: note: candidate: int Add::operator()(int&, const int&) const <near match>
         int operator()(int & _Left, const int & _Right) const//LINE I
             ^
prog.cpp:7:13: note:   conversion of argument 1 would be ill-formed:
In file included from /usr/include/c++/5/bits/stl_function.h:1128:0,
                 from /usr/include/c++/5/string:48,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:2:
/usr/include/c++/5/backward/binders.h:129:29: error: binding 'const first_argument_type {aka const int}' to reference of type 'int&' discards qualifiers
       { return op(value, __x); }
                             ^
stdout
Standard output is empty