Boost :: bind cannot work with conditional expression?

When I uncomment the conditional expression, the program will not be able 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; } 
+6
source share
1 answer

In the expression c ? x : y c ? x : y x and y must be of the same type or must be converted to others. This generic type is the type of the whole expression.

Presumably, boost::bind with a different number of parameters returns different types that cannot be converted to each other. Just because they can both be convertible to vi_t doesn't help.

+1
source

Source: https://habr.com/ru/post/897520/


All Articles