# [SDL] Setting SDL_Color = syntax error

This topic is 3934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a class which contains the variable SDL_Color textColor. In the constructor I write textColor = {0, 0, 0} to set the color but when I do, I end up with these error messages: error C2059: syntax error : '{' error C2143: syntax error : missing ';' before '{' error C2143: syntax error : missing ';' before '}' I've checked and checked again and all the { and } are there. Does anyone know what might be the mistake I've done? I have a lot of things to see if they work so a quick reply is much appriated! Thanks in advance!

##### Share on other sites
Quote:
 Original post by Obbedemuserror C2059: syntax error : '{'error C2143: syntax error : missing ';' before '{'error C2143: syntax error : missing ';' before '}'I've checked and checked again and all the { and } are there.

The compiler is telling you that the braces shouldn't be there. You can't set the coordinates of an SDL_Color via assignment using the brace notation. That only works in an initialization. Yes, I know. C and C++ are annoying that way.

You're going to have to do this:
textColor = r = 0;textColor.g = 0;textColor.b = 0;

##### Share on other sites
Ah, thank you! That makes perfectly sense! (Or not sense, depending on how you see it)

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631756
• Total Posts
3002111
×