简体   繁体   中英

passing nullptr to std::stoi

For the stoi function documented in the below reference,

http://www.cplusplus.com/reference/string/stoi/

int stoi (const string&  str, size_t* idx = 0, int base = 10);

It is then used as

int i_hex = std::stoi (str_hex,nullptr,16);

Here the idx is not defined as constant pointer (size_t * const idx =0), why can we pass nullptr as the arguments? Isn't nullptr a constant?

nullptr is not a pointer at all . It is a prvalue of type std::nullptr_t . But, it can be implicitly converted to any pointer type. Whether the pointer type is const, volatile, etc does not matter. So, the above code is fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM