How can I do the equivelant of:
#include <vector>
size_t bufferSize = 1024 * 1024;
std::vector<unsigned char> buffer(bufferSize, ' ');
With list (curly braced) initialization?
When I try to do the following:
#include <vector>
size_t bufferSize = 1024 * 1024;
std::vector<unsigned char> buffer {bufferSize, ' '};
It wrongly interprets bufferSize
as the value to be stored in the first index of the container (i.e. calls the wrong std::vector
constructor), and fails to compile due to invalid narrowing conversion from unsigned int
(size_t
) to unsigned char
.
Aucun commentaire:
Enregistrer un commentaire