No viable conversion?

#ifndef GRAPHICS_H
#define GRAPHICS_H

#include <string>
using namespace std;

#include "Color.h"
#include "utility.h"

class Graphics
{
public:

/**
* Requires: Nothing.
* Modifies: pixelData.
* Effects: Default constructor. Sets all pixels to black.
*/
Graphics();

CPP FILE:

//Default constructor
Graphics::Graphics() {
pixelData = {0};
}

I get an error at pixelData = {0}; because "No viable conversion from 'int' to 'color'. How do I solve that? I know it is an array, but I'm not sure what I'm supposed to do. Thank you!
Interesting that you haven't shown the declaration of pixelData. However, the compiler thinks it's of type color, but you've initialized it with an int, , and it cannot find a rule that it can use to convert an int to a
color
.

Maybe you should initialize it with a valid color.
The error you are getting means the compiler sees no way to take a single integer value and convert it into a 'color' . You need to find the constructor for 'color' and see how many parameters it takes and what are their types. One possibility is that 'color' can be constructed from 3 floats representing the red, green and blue channel intensity values.
So to set the first element of the array pixelData to black might look like this.
1
2
3
4
Graphics::Graphics()
        :pixelData { {0,0,0} }
{
}

The remainder of the pixelData array will be constructed using the default constructor of color which is likely to set red, green and blue channels to 0 as well.
Topic archived. No new replies allowed.