Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 VS2012在使用+;[]{}巫术_C++11_Templates_Visual Studio 2012_Lambda - Fatal编程技术网

C++11 VS2012在使用+;[]{}巫术

C++11 VS2012在使用+;[]{}巫术,c++11,templates,visual-studio-2012,lambda,C++11,Templates,Visual Studio 2012,Lambda,我希望在使用lambdas时自动推断接受函数的模板函数的参数。此示例显示了我的一些选项: template <class T> void foo(void (*func)(T)) { T val; // do something with val and func... } int main() { auto pfunc0 = [] (int) { /*...*/ }; void (*pfunc1)(int) = [] (int)

我希望在使用lambdas时自动推断接受函数的模板函数的参数。此示例显示了我的一些选项:

template <class T>
void foo(void (*func)(T)) {
    T val;
    // do something with val and func...
}

int main() {
    auto pfunc0         =  [] (int) { /*...*/ };
    void (*pfunc1)(int) =  [] (int) { /*...*/ };
    auto* pfunc2        = +[] (int) { /*...*/ };

    foo(pfunc0);      // not ok
    foo<int>(pfunc0); // ok, but redundant
    foo(pfunc1);      // ok, but redundant
    foo(pfunc2);      // ok
}
此外,它在投诉处加下划线“[”

这与(关闭为“按设计”)。VC++在x86和lambdas上支持几种调用约定(捕获列表为空),它们都提供转换。这就是为什么存在歧义的原因

不幸的是,没有列出您尚未尝试的解决方法


顺便说一句,这个bug在

中被列为已修复,我没有访问VS2012的权限,但是你是否尝试过
foo(+pfunc0);
?@krzaq我用错误消息更新了我的问题。我尝试了你的建议,但没有改变任何东西(相同的错误消息).@testman My bad,我完全错过了!@Quentin我用错误消息的图片更新了我的问题。@krzaq我读了你现在删除的答案,假设没有解决办法,忽略IDE的抱怨可以吗?还是不鼓励这样做?如果真的有问题,我可以使用更详细的代码。我安装了Visual Studio CoCommunity 2015版本14.0.25431.01更新3现在不仅是IDE,而且编译器也抱怨:/@testman我记得与Visual Studio 2015有一个命名混淆,两个版本的命名非常相似,是不同的东西:也许你是受害者?
Error: cannot deduce 'auto' type
Error: more than one conversion function from "lambda[]void (int)->void" to a build-in type applies:
function "lambda[]void (int)->void::operator void (*)(int)() const"  
function "lambda[]void (int)->void::operator void (*)(int)() const"  
function "lambda[]void (int)->void::operator void (*)(int)() const"