2012-04-20 61 views
1

我在MSVC2010中遇到了lambdas问题。C++ 0x lambda + boost :: function trouble

它是成功的编译:

auto f1 = []() { }; 
boost::function<void()> a = f1; 

但它带来的错误C2440:

auto f2 = []() 
{ 
    auto f3 = []() { }; 
    boost::function<void()> b = f3; 
}; 

错误C2440:

'initializing' : cannot convert from 'int' to 'boost::function<Signature>' 
    with 
    [ 
     Signature=void (void) 
    ] 
    No constructor could take the source type, or constructor overload resolution was ambiguous 

为什么?它在GCC4.6中工作吗?

+2

为什么你使用boost :: function而不是std :: function? – 2012-04-20 11:40:41

+0

因为我的项目的依赖库使用boost :: function。它是否适用于std :: function? – dizel3d 2012-04-20 11:44:34

+0

我用vc10测试了你的代码,但是使用了'std :: function'代替。它编译好。因此,使用clang 3.2和gcc 4.6.2的代码。我没有助推库方便,所以我不能评论你的确切问题。 HTH! – dirkgently 2012-06-07 01:26:45

回答

0

可能是MSVC中的错误(错误消息看起来非常可疑)。它适用于GCC 4.7。

+0

decltype(f3)没问题。它不是'int',它是'lambda0'。 – dizel3d 2012-04-20 11:20:33