vendredi 4 décembre 2015

Conversion from size_t to wchar_t requires a narrowing conversion

Trying to compile the following snippet of code

static std::vector<wchar_t> produceStrings(int n) {
   std::size_t vsize = 4 * n;
   auto v = std::vector<wchar_t>{ vsize };
   // ...
}

in VS2015 gives me the error:

error C2398: Element '1': conversion from 'size_t' to 'wchar_t'
requires a narrowing conversion

Replacing the definition of v by

std::vector<wchar_t> v(vsize);

however, works. Replacing vsize by, e.g., 10, works as well.

Why?

Edit: I am compiling for 32 bit.

Aucun commentaire:

Enregistrer un commentaire