Cannot convert 'this' pointer from 'const Line' to 'Line &' explanation?

Viewed 68035

This method:

bool Point::Intersects(const Line& line) const {
    return (line.ContainsPoint(*this, false));
}

causes this error: cannot convert 'this' pointer from 'const Line' to 'Line &' This change:

bool Point::Intersects(const Line& line) const {
    return const_cast<Line&>(line).ContainsPoint(*this, false);
}

fixes the error, but doesn't seem the right way to fix the issue. Why is the original method considered an error?

If it helps, ContainsPoint(const Point& point, bool isInfinite) is non-const and all methods it calls are non-const as well.

3 Answers
Related