0

我有这样的代码:

#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

错误 C3867: Foo::f: 在函数调用中没有参数列表,使用 "&Foo::f" 创建指向成员的指针

错误 C2440: =: 无法将“重载函数”转换为“std::function”

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

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

4

1 回答 1

1

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

于 2013-09-15T04:49:03.883 回答