0

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)
    {

    }
};
4
  • I know this is probably just a homework exercise. But check if your graphics lib really wants RGBA pre-multiplied by A Commented Mar 2, 2016 at 18:32
  • Is it a bad idea to multiply by A? Could you please tell me more about it? Commented Mar 2, 2016 at 18:35
  • The reason for the "A" is to change the all the colors at once, to handle overlaying images etc. Normally the graphics hardware would do the multiplication at display time. Commented Mar 2, 2016 at 18:39
  • this->rgba[0] is an error. The only thing that can appear after : is a member identifier, i.e. rgba is the only option for this class Commented Mar 2, 2016 at 21:19

2 Answers 2

4

It should be

Color(float red, float green, float blue, float alpha=1.0):
            rgba{red * alpha, green*alpha, blue*alpha, 0}
    {

    }
Sign up to request clarification or add additional context in comments.

2 Comments

This assumes a C++11 compliant compiler. Some people still aren't using C++11.
Some people haven't discovered computers yet so we should print this answer out and do a leaflet drop
0

You can use the asigment operator instead of parentetheses:

this->rgba[0](red * alpha) // wrong
this->rgba[1] = red * alpha // ok

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.