What am I doing wrong here? The compiler tells me it is a syntax error.
class Color {
private:
float rgba[4];
public:
Color(float red, float green, float blue, float alpha=1.0):
this->rgba[0] (red * alpha),
this->rgba[1] (green*alpha)
this->rgba[2] (blue*alpha)
{
}
};
asked Mar 2, 2016 at 18:29
happy_sisyphus
1,8451 gold badge20 silver badges28 bronze badges
2 Answers 2
It should be
Color(float red, float green, float blue, float alpha=1.0):
rgba{red * alpha, green*alpha, blue*alpha, 0}
{
}
answered Mar 2, 2016 at 18:30
Jarod42
229k15 gold badges215 silver badges357 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
David Hammen
This assumes a C++11 compliant compiler. Some people still aren't using C++11.
M.M
Some people haven't discovered computers yet so we should print this answer out and do a leaflet drop
You can use the asigment operator instead of parentetheses:
this->rgba[0](red * alpha) // wrong
this->rgba[1] = red * alpha // ok
Comments
lang-cpp
this->rgba[0]is an error. The only thing that can appear after:is a member identifier, i.e.rgbais the only option for this class