定义一个函数和指向该函数的指针,然后判断函数指针解引用之后是否为函数
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的类型,结果表明类型一致,但第一个输出为什么为0
已知道使用函数名调用函数时会被转化为函数函数指针
想不明白这里为什么不对
是模板匹配参数的规则造成的吗?is_function的部分实现:
template<typename> struct is_function
: public false_type { }; template<typename _Res, typename... _ArgTypes> struct is_function<_Res(_ArgTypes...)>
: public true_type { };
桃花长相依
慕慕森
随时随地看视频慕课网APP
相关分类