c++ - Pointers and enum in C -
i'm trying rewrite c++ code c , got problems comparising enum pointers. please take look.
enum:
enum state{title,play,lost}
my function looks that:
void changestate(int *state, int newstate) { state = newstate; if (state == title) { /* */ } else if (state == play) { /* something2 */ } else if (state == lost) { /* something3 */ } }
and when try calling function by:
changestate(&state, title)
etc. doesn't work correctly. when put in code:
if (state == title) { /* instructions */ }
what mistake? advance time.
you need dereference pointer (use *state
) read value points to
this means code should change to
void changestate(int *state, int newstate) { *state = newstate; if (*state == title) { /* */ } else if (*state == play) { /* something2 */ } else if (*state == lost) { /* something3 */ } }
Comments
Post a Comment