Passing object of class/constructor errors
<p>I'm currently writing the implementation file of a program I'm doing. I included the header file in it which is why you don't see as much as you would usually see</p>

<p>This is the program in which all the functions you see are included in a class called "Body". The member functions are public except for the <code>std::istream</code> which is considered "friend" and the variables are private</p>

<p>I'm trying to understand why I am getting this error:</p>

<blockquote>
  <p>"passing const Body as 'this' argument of double Body::getX() discards qualifiers"</p>
</blockquote>

<p>This error is pointing to my <code>distanceTo</code> function that I wrote. I kind of understand what the error message is saying but I really need the passing argument of <code>distantTo</code> function to be constant. Any way of fixing this?</p>

<p>This is the overall view of my program:</p>

<pre><code>#include "Body.h"
#include &lt;cmath&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;


Body::Body(std::string _name, double _mass, double _x, 
    double _y, double _vx, double _vy)
{
    name = _name;
    mass = _mass;
    x = _x;
    y = _y;
    vx = _vx;
    vy = _vy;
}

double Body::getX()
{
    return x;
}

double Body::getY()
{
    return y;
}

double Body::getVX()
{
    return vx;
}

double Body::getVY()
{
    return vy;
}

double Body::getMass()
{
    return mass;
}

void Body::setX(double _x)
{
    x = _x;
}

void Body::setY(double _y)
{
    y = _y;
}

void Body::setVX(double _vx)
{
    vx = _vx;
}

void Body::setVY(double _vy)
{
    vy = _vy;
}

void Body::draw(Canvas &amp;canvas)
{
    canvas.DrawCircle(getX(), getY(), 10);
    canvas.DrawText(getX()+2, getY(), name);
}


istream &amp;Body::operator&gt;&gt;(std::istream &amp;input, Body &amp;body)
{

    input &gt;&gt; body.name &gt;&gt; body.mass &gt;&gt; body.x &gt;&gt; body.y &gt;&gt; body.vx &gt;&gt; body.vy;

    return input;

}


double Body::distanceTo(const Body &amp;other)
{
    double tx = x-other.getX(); 
    double ty = y-other.getY();
    double ans = sqrt(tx*tx + ty *ty);

    return ans;
}

double Body::forceX(double G, const Body &amp;body)
{
    double d = distanceTo(body);
    double d3=d*d*d;
    double tx = x - getX();
    double dx= sqrt( tx * tx );
    double fx = G * ((mass * getMass() * dx) / d3);

    return fx;      
}

double Body::forceY(double G, const Body &amp;body)
{
    double d = distanceTo(body);
    double d3=d*d*d;
    double ty = y - getX();
    double dy= sqrt( ty * ty );
    double fy = G * ((mass * getMass() * dy) / d3); 

    return fy;  
}
</code></pre>

<p>Private data:</p>

<pre><code>std::string name;
double x, y;
double vx, vy;
double mass;
</code></pre>
