user869210
user869210

Reputation: 231

boost::bind can't work with conditional expression?

When I uncomment the conditional expression, the program will fail to compile under visual c++ 2008.

#include <iostream>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
typedef boost::function<void(int, int)> vii_t;
typedef boost::function<void(int)> vi_t;

void foo(int a, int b){}
void bar(int a){}
int main(int argc, char* argv[])
{
    //vi_t test= true ? boost::bind(foo, _1, 100) : boost::bind(bar, _1);
    vi_t test1 = boost::bind(foo, _1, 100);
    vi_t test2 = boost::bind(bar, _1);
    //test(1);
    test1(1);
    test2(1);
    return 0;
}

Upvotes: 6

Views: 294

Answers (1)

Bo Persson
Bo Persson

Reputation: 92241

In the expression c ? x : y x and y must be of the same type, or one must be convertible to the other. That common type is the type of the whole expression.

Presumably, boost::bind with different number of parameters return different types that are not convertible to each other. That they both might be convertible to vi_t doesn't help.

Upvotes: 1

Related Questions