Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.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++ 为什么在解引用函数指针上使用std::is_函数时计算为false?_C++_C++11_Function Pointers_Typetraits - Fatal编程技术网

C++ 为什么在解引用函数指针上使用std::is_函数时计算为false?

C++ 为什么在解引用函数指针上使用std::is_函数时计算为false?,c++,c++11,function-pointers,typetraits,C++,C++11,Function Pointers,Typetraits,我试图使用std::is_function来确定变量是否是函数指针 当运行以下代码时 #include <iostream> #include <typeinfo> using namespace std; int main() { typedef int(*functionpointer)(); functionpointer pmain = main; cout << typeid(functionpointer).name

我试图使用
std::is_function
来确定变量是否是函数指针

当运行以下代码时

#include <iostream>
#include <typeinfo>

using namespace std;

int main() {
    typedef int(*functionpointer)();

    functionpointer pmain = main;

    cout << typeid(functionpointer).name() << " "<< is_function<functionpointer>::value << endl;
    cout << typeid(decltype(pmain)).name() << " " << is_function<decltype(pmain)>::value << endl;

    cout << typeid(decltype(main)).name() << " " << is_function<decltype(main)>::value << endl;
    cout << typeid(decltype(*pmain)).name() << " " << is_function<decltype(*pmain)>::value << endl;

    return 0;
}
有见识的人能解释一下为什么
std::is_function
的最后一个表达式的计算结果为false吗


(在g++4.7、g++4.8和clang++3.2下测试的代码)

这是因为decltype(*pmain)产生了对函数类型的引用,对于该函数类型,std::functionfalse。尝试:

is_function<remove_reference<decltype(*pmain)>::type>::value
是函数::值
的地址。
is_function<remove_reference<decltype(*pmain)>::type>::value