I\'ve been looking into this for a few hours, to no avail. Basically I have
struct rectangle {
int x, y, w, h;
};
rectangle player::RegionCoordinates() // R
Given the kind of error you are getting, I must assume RegionCoordinates()
is returning an object by value, thus causing the creation of a temporary, and you are taking the address of that temporary.
The address-of operator requires an lvalue as its operand, but you are applying it to an rvalue (temporaries are rvalues).
You could do this (if you are not using C++11, replace auto
with the type returned by RegionCoordinates
):
auto rcPlayer1 = player1.RegionCoordinates();
auto rcStick1 = player1.RegionCoordinates();
if (IsCollision(&rcPlayer1, &rcStick1)) //ERROR
{
player1.score+=10;
stick1.x = rand() % 600+1;
stick1.y = rand() % 400+1;
play_sample(pickup,128,128,1000,false);
}
Alternatively, you can change IsCollision
so that it accepts references rather than pointers, as suggested by Angew in his answer.