[英]passing nullptr to std::stoi
对于以下参考文献中记录的 stoi function,
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传递为arguments? nullptr 不是常数吗?
nullptr
根本不是指针。 它是std::nullptr_t
类型的纯右值。 但是,它可以隐式转换为任何指针类型。 指针类型是 const、volatile 等都无关紧要。 所以,上面的代码没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.