Big confusion around here.
Like jcl said, if you only want to compare two positions along the x axis it very simple:

You need to have the pointers defined for the two entities, so:
if(entity1.x < entity2.x) //entity1 behind entity2
{
...
}
I cant see where is the problem here.
You can do that with vectors too but this way its simpler.
Edit: Thunder was faster
