language: C++ 4.7.2 (gcc-4.7.2)
date: 570 days 22 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <algorithm>
#include <iterator>
#include <boost/bind.hpp>
 
struct S {
  bool ascending;
  bool Compare(int lhs, int rhs) {
    return ascending ? (lhs < rhs) : (rhs < lhs);
  }
};
 
int main () {
 
  int i[] = { 1, 3, 5, 7, 8, 6, 4, 2 };
  S s;
  s.ascending = true;
  std::sort(i, i+8, boost::bind(S::Compare, &s, _1, _2));
  std::copy(i, i+8, std::ostream_iterator<int>(std::cout, " "));
  std::cout << "\n";
 
  s.ascending = false;
  std::sort(i, i+8, boost::bind(S::Compare, &s, _1, _2));
  std::copy(i, i+8, std::ostream_iterator<int>(std::cout, " "));
  std::cout << "\n";
}
prog.cpp: In function ‘int main()’:
prog.cpp:18: error: invalid use of non-static member function ‘bool S::Compare(int, int)’
prog.cpp:23: error: invalid use of non-static member function ‘bool S::Compare(int, int)’