Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-03-25 11:11:46


On Monday 25 March 2002 10:43 am, you wrote:
> Since my first post using the web interface seems to have been lost, I'm
> trying again via email...
>
> Is it just me or is it my compiler (MSVC6SP5)? The following code gives me
> an error. Whats wrong?
>
> #include <boost/bind.hpp>
> #include <functional>
>
> using boost::bind;
>
> void main()
> {
> bind(std::greater<int>, _1, _2)(1, 2);
> }
>
> main.cpp(8) : error C2275: 'std::greater<int>' : illegal use of this type
> as an expression
>
> TIA, Markus

Two problems here:
  - std::greater<int> is a type. You want std::greater<int>() to create an
object of that type
  - constants can't (directly) be passed into boost::bind objects. You'll
need to have: int x = 1, int y = 2; and call the boost::bind object with (x,
y) instead of (1, 2).

If you still get errors, then it's your compiler's fault because it can't
figure out the return type. You'll have to tell bind to use an 'int' return
type, so the final code would look like this:

#include <boost/bind.hpp>
#include <functional>

using boost::bind;

int main()
{
  int x1 = 1;
  int x2 = 2;
  bind<int>(std::greater<int>(), _1, _2)(x1, x2);
}

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net