1. 头文件必须引入cpp运行#include type_traits #include iostream2. 核心语法老式写法C11cpp运行std::is_pointerT::value简化写法C17 推荐cpp运行std::is_pointer_vT返回booltrue是指针类型false不是。3. 判断类型是不是指针cpp运行#include type_traits #include iostream int main() { std::cout std::boolalpha; // 普通类型 std::cout std::is_pointer_vint \n; // false std::cout std::is_pointer_vdouble \n; // false // 一级指针 std::cout std::is_pointer_vint* \n; // true std::cout std::is_pointer_vdouble* \n; // true // 二级指针 也是指针 std::cout std::is_pointer_vint** \n; // true // 引用不是指针 std::cout std::is_pointer_vint \n; // false // 数组不是指针 std::cout std::is_pointer_vint[5] \n; // false return 0; }4. 判断变量是不是指针用decltype(变量)取变量类型再给is_pointercpp运行int main() { int a 10; int* p a; int r a; std::cout std::boolalpha; std::cout std::is_pointer_vdecltype(a) \n; // false std::cout std::is_pointer_vdecltype(p) \n; // true std::cout std::is_pointer_vdecltype(r) \n; // false }5. 模板中做类型分支编译期判断cpp运行template typename T void checkType() { if constexpr (std::is_pointer_vT) { std::cout 这是指针类型\n; } else { std::cout 不是指针类型\n; } } // 调用 checkTypeint(); checkTypeint*(); checkTypeint**();6. 关键注意点std::is_pointer只识别原生指针T*智能指针std::shared_ptr/std::unique_ptr判断为 false引用T不是指针判 false数组T[N]不是指针判 false是编译期判断无运行时开销7. 一句话记忆类型直接填std::is_pointer_vint*变量用decltype包一层std::is_pointer_vdecltype(var)C17 用_v后缀更简洁。