void Image::create (unsigned int width, unsigned int height, const Uint8 *pixels);
std::vector<sf::Uint8> pixels;
sf::Image image;
image.create(sizeX, sizeY, pixels.data());
std::vector<sf::Uint8> pixels;
// fill pixels...
sf::Uint8* dat = new sf::Uint8[pixels.size()];
std::copy(pixels.begin(), pixels.end(), dat); // copy them somehow..
sf::Image image;
image.create(sizeX, sizeY, dat);
delete[]dat;
Option (b) will only work with the very latest compilers, so I'd recommend option (a). i.e.,Wow, this is so wrong and unnecessary (see the other answer(s)) :P
QuoteOption (b) will only work with the very latest compilers, so I'd recommend option (a). i.e.,Wow, this is so wrong and unnecessary (see the other answer(s)) :P
I disagree, you shouldn't be afraid to copy your data between structures. If the OP had a std::list for example, this method is the only option, so it's good to know.But it's not a std::list. So it is wrong and misleading to give such an answer (and to add "most compilers don't support it" ???).
Option (b) will only work with the very latest compilers, so I'd recommend option (a). i.e.,That's just flat-out wrong. Based on vector's definition in the standard, it's safe and has always been safe (in any sane implementation of std::vector) to use &pixels[0] in place of data().
QuoteI disagree, you shouldn't be afraid to copy your data between structures. If the OP had a std::list for example, this method is the only option, so it's good to know.But it's not a std::list. So it is wrong and misleading to give such an answer (and to add "most compilers don't support it" ???).