Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/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++ 为什么VC++;在clang不运行时编译代码';T_C++_C++11_Visual C++_Compiler Errors_Clang - Fatal编程技术网

C++ 为什么VC++;在clang不运行时编译代码';T

C++ 为什么VC++;在clang不运行时编译代码';T,c++,c++11,visual-c++,compiler-errors,clang,C++,C++11,Visual C++,Compiler Errors,Clang,我使用VS 2015(更新3)编译以下代码: #include <codecvt> #include <cctype> #include <functional> int main() { std::function<int(int)> fn = std::isspace; } 根本原因是什么?std::isspace不明确,它可以指在中找到的与C兼容的代码,也可以指在中找到的代码 您可以使用 std::function<int(

我使用VS 2015(更新3)编译以下代码:

#include <codecvt>
#include <cctype>
#include <functional>

int main()
{
    std::function<int(int)> fn = std::isspace;
}

根本原因是什么?

std::isspace
不明确,它可以指在
中找到的与C兼容的代码,也可以指在
中找到的代码

您可以使用

std::function<int(int)> fn = static_cast<int(*)(int)>(std::isspace);
std::function fn=static_cast(std::isspace);
或者通过省略
std::
名称空间,尽管从技术上讲,不需要实现将C函数导入全局名称空间


的Clang和GCC实现似乎都包含来自
的模板声明,因此出现了错误;想必VS没有。

std::isspace
在标准库中重载

由于标准库头的结构,一个编译器可以看到两种不同的名称声明

那么,在没有参数或强制转换的情况下使用它是不明确的

std::function<int(int)> fn = static_cast<int(*)(int)>(std::isspace);