当我取消注释条件表达式时,程序将无法在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;
}
Run Code Online (Sandbox Code Playgroud)
在表达式中,c ? x : yx 和 y 必须是同一类型,或者其中一个必须可以转换为另一个。该公共类型是整个表达式的类型。
据推测,boost::bind不同数量的参数返回不同的类型,这些类型不能相互转换。它们都可以转换成vi_t没有帮助。
| 归档时间: |
|
| 查看次数: |
271 次 |
| 最近记录: |