得到錯誤 幫助需要調用功能從結構
struct Point {
double x , y ;
double del ;
Point() {}
Point (double _x , double _y){ x = _x; y = _y;}
double Dist(const Point &P){ double dx = x - P.x ; double dy = y - P.y; return sqrt(dx*dx + dy *dy);}
};
int ccw (Point p,Point q ,Point r)
{
double val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
if(fabs(val) < EPS) return 0;
if(val > EPS) return 1;
else return 2 ;
}
struct seg2 {
Point a, b;
seg2(){}
seg2(Point _a ,Point _b){a = _a;b= _b;}
double length(){ return a.Dist(b);}
bool onseg(const Point &p) {
return (a.Dist(p) + b.Dist(p) - length() < 0);
}
bool isIntersect (const seg2& S){
int o1 = ccw(a, b, S.a);
int o2 = ccw(a, b, S.b);
int o3 = ccw(S.a, S.b, a);
int o4 = ccw(S.a, S.b, b);
if(o1 != o2 && o3 != o4){
return true;
}
if(o1 == 0 && onseg(S.a)) return true;
if(o2 == 0 && onseg(S.b)) return true;
if(o3 == 0 && S.onseg(a)) return true; // Here I want to call S.onseg
if(o4 == 0 && S.onseg(b)) return true; // Here
return false;
}
};
我給出的這個錯誤
member function 'onseg' not viable: 'this' argument has type 'const seg2',
but function is not marked const
if(o3 == 0 && S.onseg(a)) return true;
'onseg' declared here
bool onseg(const Point &p) {
member function 'onseg' not viable: 'this' argument has type 'const seg2',
but function is not marked const
if(o4 == 0 && S.onseg(b)) return true;
'onseg' declared here
bool onseg(const Point &p) {
這是一個程序,兩個線段相交或不 但我不能調用onseg函數從結構 :( C++代碼.. 這給我編譯錯誤.. 我該怎麼打電話?
您至少需要給我們看到的錯誤 –
@ Matrix.code [在您的問題當然!](http://stackoverflow.com/posts/27733184/edit) –