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

后端 未结 3 1041
南方客
南方客 2021-01-30 12:54

This method:

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

causes this error: cannot co

3条回答
  •  误落风尘
    2021-01-30 13:33

    In this case you are calling a non-const method on a const reference which isn't allowed. You have two options:

    1. Do what you did and const_cast
    2. Make ContainsPoint a const method

提交回复
热议问题