I don't have the graphics libraries to run your simulation. How do you know that the gravitational force is not applied?
The only timestepping you do is in render() (via e.render()) where you do a single timestep. How many times do you call this function? One timestep is only 24000 s (about 7 hours) - Mercury's orbital period is about 88 days, so it will only move about 1 degree of arc in that time.
One way of testing the gravitational attraction is to temporarily set Mercury's initial velocity to zero. Then it should move (faster and faster) toward the sun.
double* Body::attraction(Body other) {
...
double arrayF[1]; // Note: this is a local variable. The pointer to it becomes invalid as soon as the function attraction(...) ends.
arrayF[0] = cos(theta) * F;
arrayF[1] = sin(theta) * F;
return arrayF;
}
I think double arrayF[1];
only creates a one-element array anyway. You need two components.
A struct to hold your vector force components (and positions, and velocities) would be a good idea. Actually, so would a valarray: then you don't need to do x and y components separately.
Have you checked (by printing out) what is actually in fx, fy and timestep before these lines, and what are the values of position and velocity afterward.
Also, it would make your code much simpler if you made fx and fy into data members of class Body - then you wouldn't need this confusing extra class BodyForce.