I’ve asked in one of my posts a question about alternative to boost::lexical_cast and amongst many replies I’ve got one suggestion stoi as a viable alternative.
I’ve decided to test it and to my surprise as a second argument to this function (argument describing size) is a pointer to size_t type, not actual size_t type. Is there any logical explanation for that and in what way it is better to have a pointer to actual object than object itself (just in this particular case when size is concerned and I wouldn’t instinctively assign size with pointer)?
Link to stoi doc: http://msdn.microsoft.com/en-us/library/ee404860.aspx
That is a way of having optional arguments. Basically, if you are interested in knowing which is the first character that was not converted into the number. If you are not really interested in that result, you can pass nullptr.
This is meant to be used as:
By using a pointer you can make the argument really optional, if it was an out parameter, but required a reference would be used, but that would require user code to create the variable always regardless of whether they are interested in the value or not, so it would not be really optional.