C ++ style and converting 0 to size_t (0)

Does size_t(0)it use the same as used 0in the following code?

   const string foo = "testing";
   const size_t pos = foo.find("i");
   string name = foo.substr(size_t(0), pos);

That is, when I bet only 0, does it convert to size_t(0)? If so, is one form preferable to another? I guess it t(0)is the best because it makes the conversion explicit. On the other hand, perhaps some programmers consider size_t(0)verbose? I guess in practice nobody cares.

+3
source share
2 answers

That is, when I put only 0, will it convert to size_t (0)?

The conversion is implicit because substr:

basic_string substr( size_type pos = 0,
                     size_type count = npos );

Thus, your listing is redundant.

+4
source

0 , , , .

string substr ( size_t pos = 0, size_t n = npos ) const;

.

+1

All Articles