int* iShotsFired = (int*)(localPlayer + m_iShotsFired); why adding "(int*)" ? isnt…
- User
int* iShotsFired = (int*)(localPlayer + m_iShotsFired);
why adding "(int*)" ? isnt "iShotFired" being interpreted as an int pointer already ?
Assistant
In the expression:
cint* iShotsFired = (int*)(localPlayer + m_iShotsFired);the
(int*)is a cast. It's used to tell the compiler to treat the result of the expression(localPlayer + m_iShotsFired)as a pointer to anint, regardless of the actual types oflocalPlayerandm_iShotsFired.Without the cast, the compiler would attempt to perform pointer arithmetic based on the types of and . If is a pointer to a structure or a class, and is an offset within that structure or class, the result of the addition would still be a pointer to the same type as . However, the intention here is to treat the result as a pointer to an , which is why the cast is necessary.