gpt4 book ai didi

c++ - VS C++ 2012(13) 无法将重载函数转换为 std::function

转载 作者:行者123 更新时间:2023-11-28 07:25:26 25 4
gpt4 key购买 nike

我有这样的代码:

#include <functional>

struct Foo {
template<typename T>
static void f(int);
};

template<>
void Foo::f<int>(int) {}

int main()
{
std::function<void(int)> func;
//func = static_cast<void (*)(int)>(Foo::f<int>);/works
func = Foo::f<int>;//compilation failure
return 0;
}

VS 2012 和 2013 预览版在以下行给出编译时错误:

func = Foo::f<int>;//compilation failure

error C3867: Foo::f: in function call no argument list, use "&Foo::f" to create pointer to member

error C2440: =: can not convert "overloaded-function" into "std::function"

但是gcc 4.8.1、clang 3.3和Intel Compiler 13.1.3编译此代码带有选项 (-Wall -pedantic -std=c++11) 没有任何警告和错误。

那么这是Visual Studio C++编译器的编译器bug吗?

最佳答案

是的,这是一个错误,visual studio 2013 rc 可以毫无问题地编译它,所以看起来他们已经修复了它。

关于c++ - VS C++ 2012(13) 无法将重载函数转换为 std::function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18808941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com