定義一個函數(shù)和指向該函數(shù)的指針,然后判斷函數(shù)指針解引用之后是否為函數(shù)void test1() {}int main(){ void(*t1)() = test1; std::cout << std::is_function<decltype(*t1)>::value << std::endl; std::cout << std::is_function<decltype(test1)>::value << std::endl; std::cout << (typeid(decltype(test1)).hash_code() == typeid(decltype(*t1)).hash_code()) << std::endl;
return 0;
}最后輸出為:011直接比較*t1和test1的類型,結(jié)果表明類型一致,但第一個輸出為什么為0已知道使用函數(shù)名調(diào)用函數(shù)時會被轉(zhuǎn)化為函數(shù)函數(shù)指針想不明白這里為什么不對是模板匹配參數(shù)的規(guī)則造成的嗎?is_function的部分實現(xiàn):template<typename> struct is_function
: public false_type { }; template<typename _Res, typename... _ArgTypes> struct is_function<_Res(_ArgTypes...)>
: public true_type { };
c++函數(shù)指針解引用之后為什么不是函數(shù)了?
嗶嗶one
2018-07-01 08:02:57