本文介绍了运算符+ on Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我指出为什么这在VS2013中不起作用。

  auto p = + [] > void {std :: cout< Hello,world!\\\
; };
p();

source_file.cpp(7):错误C2593:'operator +'是不明确的
可以是内置的C ++操作符+(void(__cdecl *)(void))'
或'内置的C ++操作符+(void(__fastcall *)(void))'
或'内置的C ++操作符(void(__stdcall *) C ++操作符+(void(__vectorcall *)(void))'

转换lambda

我如何告诉编译器他应该使用什么转换?

解决方案显然这是一个VC ++错误。看起来没有别的方法可以显式地转换:

  + static_cast< void(*)()>([] {}); //空白兰布不失一般性

不幸的是,魔法会像这样丢失。


Can anyone help me pointing out why this does not work in VS2013?

auto p = +[]() -> void { std::cout << "Hello, world!\n"; };
p();

source_file.cpp(7) : error C2593: 'operator +' is ambiguous
    could be 'built-in C++ operator+(void (__cdecl *)(void))'
    or       'built-in C++ operator+(void (__stdcall *)(void))'
    or       'built-in C++ operator+(void (__fastcall *)(void))'
    or       'built-in C++ operator+(void (__vectorcall *)(void))'

This is a legal operator to force-cast the lambda

How can I tell the compiler what conversion he should use?

解决方案

Apparently this is a VC++ bug. There seems to be no other way than to explicitly cast:

+ static_cast< void(*)() >( []{} ); // Empty lamba without loss of generality

Unfortunately, the magic is lost like this.

这篇关于运算符+ on Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:48
查看更多