I have a Point2D class as follows:
class Point2D{
int x;
int y;
public:
Point2D(int inX, int inY){
x = inX;
y = inY;
};
int getX(){return x;};
int getY(){return y;};
};
Now I have defined a class Line as:
class Line {
Point2D p1,p2;
public:
LineVector(const Point2D &p1,const Point2D &p2):p1(p1),p2(p2) {
int x1,y1,x2,y2;
x1=p1.getX();y1=p1.getY();x2=p2.getX();y2=p2.getY();
}
};
Now the compiler gives the error in the last line( where getX() etc are called):
error: passing `const Point2D' as `this' argument of `int Point2D::getX()' discards qualifiers
If I remove the const keyword at both places, then it compiles successfully. What is the error? Is it because getX() etc are defined inline? Is there any way to recify this retaining them inline?