My first time trying to use bitmasking so I went to Stack Overflow and it showed doing it like this. The popular answer was edited in 2018 so I thought maybe something has changed in C++17 but I looked at some old tutorials and I can’t see any difference. I tried casting to uint8 first and using char instead… no joy.
#define BARRIER_RIGHT 4; //This is at the top of the .cpp - could be the problem line?
uint8 flags = Board->GridArray[CellID].Boundaries;
if ((flags & (BARRIER_RIGHT) == BARRIER_RIGHT) // this is line (481)
{
}
Compiler Errors:
2>\GridProjectGameMode.cpp(481): error C2143: syntax error: missing ‘)’ before ‘;’
2>GridProjectGameMode.cpp(481): error C2429: language feature ‘init-statements in if/switch’ requires compiler flag ‘/std:c++17’
2>GridProjectGameMode.cpp(481): error C2059: syntax error: ‘)’
EDIT:
Ok I typed the line as you did (which is what I had originally but I’ve been messing around with it)
if (flags & (BARRIER_RIGHT)==BARRIER_RIGHT) // this is line (481)
{
}
The proper error readout is as follows…
GridProjectGameMode.cpp(481): error C2143: syntax error: missing ‘)’ before ‘;’
GridProjectGameMode.cpp(481): error C4552: ‘&’: result of expression not used
GridProjectGameMode.cpp(481): error C2429: language feature ‘init-statements in if/switch’ requires compiler flag ‘/std:c++17’
GridProjectGameMode.cpp(481): error C2059: syntax error: ‘)’
#define BARRIER_RIGHT 4; //This is at the top of the .cpp - could be the problem line?
Funny, this was the problem all along, I have never written my own #define before. I had erroneously added a semi-colon! I couldn’t understand why I was able to use BARRIER_RIGHT previously with no problem, the reason being I used it at the end of lines of code. Since C++ allows as many ;;;;;; as you want at the end of a line I didn’t pick up the error! :rolleyes: Thanks redbox, your input helped me weed out the issue as I trusted your code to work. ~Stef