compare pointer to int without new var
I made a class, and I know what the problem is, but I don't know how to fix the problem the way I want to. I want to compare a pointer to an int, but without creating a new variable. For my case, doing this is very trivial, as I do not need to worry about operation time on such a small game as mine, but I just want to get in the habit of creating efficient code, whether I need it or not.
Now nudging on, I have made a class, and I have found the problem from the compiler error, I am not allowed to compare a pointer to a int, but is there some way to get around this without making a new variable, as the whole point is of me using a pointer is to conserve memory.
Here's my class.
void set_cords(int pong_x, int pong_y); // points pointers
void speed_x(); //chages outside pong positions
int *ptr_x; // to acces pong pos out of class
bool x_dir; // tells which way pong is travling
void pong_movement::set_cords(int pong_x, int pong_y)
ptr_x = &pong_x;
ptr_y = &pong_y;
y_dir = false; // y starts at top and moves down, thus starts false
x_dir = true;
if (ptr_x <= 0 | x_dir) //
x_dir = true;
else if(ptr_x >= 455 | !x_dir)
x_dir = false;
if (ptr_y <= 0 | !y_dir) //
y_dir = false;
else if(ptr_y >= 615 | !y_dir)
y_dir = true;
Will the pointers be assigned the address of the outside vars, or does the class create a new variable when a the function is called? I will initiate the class at the beginning of the program with pong::set_cords then I will use speed_x/y in a while loop of the game. Will this work behind the whole theory of my class?