c++ - 将 nullptr 传递给 std::stoi
问题描述
对于以下参考文献中记录的 stoi 函数,
http://www.cplusplus.com/reference/string/stoi/
int stoi (const string& str, size_t* idx = 0, int base = 10);
然后它被用作
int i_hex = std::stoi (str_hex,nullptr,16);
这里idx没有定义为常量指针(size_t * const idx =0),为什么我们可以传递nullptr作为参数呢?nullptr 不是常数吗?
解决方案
nullptr
根本不是指针。它是类型的prvaluestd::nullptr_t
。但是,它可以隐式转换为任何指针类型。指针类型是 const、volatile 等都无关紧要。所以,上面的代码没问题。
推荐阅读
- python - dask.visualize() 无法显示单词
- dax - DAX 查询 - 从 powerbi 中的表中过滤掉值
- business-objects - 使用 BO 进行多维分析
- python - Pandas\Python:如何计算列中最后一个相同值的数量
- amazon-web-services - Simba ODBC Athena 驱动程序无法与 IAM 配置文件身份验证连接
- php - the_field() 函数将值放在错误的位置
- android - Android adb 无法访问并在 Android Studio 中自行重启
- python - 在计算给定大型数据集的项目和频率后创建两个单独的文本文件
- node.js - NestJS - 电子邮件验证无法正常工作
- wpf - WPF DataGrid - 禁用 DataGridCheckBoxColumn