My problem is that no matter how I change my struct’s +=
overload, I always get the same error:
In static member function 'static void float3::graviton(const Particle&, const Particle&)':
error: passing 'const float3' as 'this' argument discards qualifiers [-fpermissive]
p_p1.v += force;
Where the force
variable is highlighted as the source of the error.
The static member function static void float3::graviton(const Particle&, const Particle&)
is defined as follows:
// float3.cpp
void float3::graviton(const Particle& p_p1, const Particle& p_p2) {
float force = Physics_G * (p_p1.m * p_p2.m) / (p_p2.p - p_p2.p).magnitudeSquared();
p_p1.v += force;
p_p2.v += force;
}
float3
is a struct that declares graviton as: static void graviton(const Particle& p_p1, const Particle& p_p2);
Particle
is a seperate struct outside of the header or cpp file for float3
with 3 fields:
-
v
a float3 -
m
a float -
p
a float3
Names prefixed with Physics_
are constants defined in another seperate header file.
magnitudeSquared
is a float3 member function that returns a float.
Finally, the definition for the operator +=
between a float3 and a float is:
// float3.h
inline void float::operator+=(float p_scalar) {
this->x += p_scalar;
this->y += p_scalar;
this->z += p_scalar;
}
I have tried many things from not returning *this
with the operator function, and moving the graviton function to other places. Could anyone help me find why I still get this error?
If I am missing any required information I am happy to give more.