Question: Need help on how to correctly initialize pixels_ as a vector(int) constructor as asked in Part 2. using UC = unsigned char; struct Pixel {UC

Need help on how to correctly initialize pixels_ as a vector(int) constructor as asked in Part 2.

Need help on how to correctly initialize pixels_ as a vector(int) constructor

using UC = unsigned char; struct Pixel {UC red=0, green=0, blue=0, alpha=255;};

class Image { public: //Initializors Image() = default; Image(unsigned width, unsigned height); Image(const std::string& path); //Accessors unsigned width() const; unsigned height() const; unsigned size() const; //Mutators void fill(const Pixel& color); //Overloaded functions Pixel& at(unsigned pos); Pixel& at(unsigned x, unsigned y);

bool load(const std::string& path); bool save(const std::string& path); private: unsigned width_ = 0, height_ = 0; vector pixels_; };

Image::Image(unsigned width, unsigned height) { width_ = width; height_ = height; vector(pixels_); } Image::Image(const string& path) { width_ = 0; height_ = 0; } unsigned Image::width() const { return width_; } unsigned Image::height() const { return height_; } unsigned Image::size() const { return pixels_.size(); }

Sorry this is not complete source code, but I just want to know again how to correctly initialize for pixels_ as per the instructions.

2. The two-argument constructor needs to initialize width_ and height, as well as pixels. Initialize pixels using the vector(int) constructor which creates a vector containing width * height Pixels

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!