ok well i have structure
struct balls {
balls(UINT_PTR const &val) : BALL_ID(val){}
int Ex;
int Ey;
const UINT_PTR BALL_ID;
};
balls ball1(0x1);
and i have a switch statement
switch(wParam)
{
case ball1.BALL_ID:
if(ball1.Ex<300)
{
ball1.Ex++;
}
else
{
KillTimer(hWnd, ball1.BALL_ID);
}
InvalidateRect(hWnd, rect, false);
break;
case SCORECOUNTER_ID:
if(life==0)
{
if(scorecounter<1000)
{
scorecounter+=100;
_swprintf(str, _T("Score: %d"), scorecounter);
InvalidateRect(hWnd, rect, false);
}
else
{
_swprintf(level, _T("Level: %d"), 2);
InvalidateRect(hWnd, rect, false);
}
}
break;
}
i get an error thatball1.BALL_ID is not constant the second line should solved this but it didn’t any idea?
The
caselabels must be integral constant expressions — they must be evaluable during translation (i.e. at compile). In this case,BALL_IDcannot be evaluated at compile-time. Differentballobjects are allowed to have differentBALL_IDvalues, hence the compiler cannot possibly evaluate it during translation. Futher, the.(member resolution operator for objects) cannot be used in a case label (i.e. even if you did makeBALL_IDstaticit wouldn’t work for you).I would hazard a guess that
SCORECOUNTER_IDis a macro/static const intand is hence evaluable by the compiler.You can use a namespace scope
enumorintto fix this. E.g: