'+ =': pointer to the left; needs the integral value on the right

I'm confused. Can't I use this on a float? It must be an integer? I am trying to define it as a point, but I guess I cant convert float to float *

//global definition
float g_posX = 0.0f;

&g_posX -= 3.03f;

      

+2


a source to share


5 answers


You probably just want to do this:

float g_posX = 0.0f;
g_posX -= 3.03f;

      



What your code is trying to do is take the address g_posX

and subtract it 3.03f

from the address. This doesn't work for two reasons:

  • The address is not an lvalue: it cannot be assigned. Assigning an address would be meaningless. What would it do if you move the variable in memory?
  • Pointer arithmetic can only be done using integers. There are no fractional addresses.
+18


a source


If you want to subtract from float, then just specify the variable and don't take its address:

g_posX -= 3.03f;

      



Otherwise, it &g_posX

is rvalue

which you cannot assign to it.

+3


a source


well, it &g_posX

's a pointer to float. Pointers are memory addresses and (more or less) intereger. To increase the float, just remove &

.

0


a source


You don't need g_posX before, just do the math like

g_posX -= 3.03f;

      

0


a source


Increment and decrement operators

are defined only for integer data types, not for floating point, double, etc.

-1


a source







All Articles