#include<iostream>using namespace std;#include<cmath>struct point{ double x;double y;};class Quad{ public:Quad( int t1,int t2 ){ a.x=t1;a.y=t2;}point a;};double d( point &a,point &b ){ return sqrt( pow( (a.x-b.x),2) - pow( a.y-b.y,2 ) ); }int main(){ double a,b,c,d,e,f,g,h;while( cin>>a>>b>>c>>d>>e>>f>>g>>h ){ Quad p1( a,b );Quad p2( c,d );Quad p3( e,f );Quad p4( g,h );cout<<fabs( d(p1.a,p2.a)-d(p3.a,p4.a) )<<endl;}}錯在哪?
2 回答

藍山帝景
TA貢獻1843條經驗 獲得超7個贊
沒試過,但你想一下調用一個類的局部函數的形式應該是 (對象).(函數)()的形式,而你的funcList調用 明顯缺少對象.
試了一下簡單的例子,可運行成功.
class A
{
public:
bool B(){ return true;}
bool C(){ return false; }
};
void main(int argc, char ** argv)
{
A a;
bool (A::*funTest[2])() = {A::B, A::C}, d[2];
d[0] = (a.*funTest[0])();
d[1] = (a.*funTest[1])();
}

嗶嗶one
TA貢獻1854條經驗 獲得超8個贊
#include<iostream> using namespace std; #include<cmath> struct point { double x; double y; }; class Quad { public : Quad( int t1, int t2 ) { a.x=t1; a.y=t2; } point a; }; // 函數名為d跟main里面的d同名,不可見??筛臑閐d double d( point &a,point &b ) { return sqrt ( pow ( (a.x-b.x),2) - pow ( a.y-b.y,2 ) ); } int main() { double a,b,c,d,e,f,g,h; // 變量d跟函數d同名。請改其中之一 while ( cin>>a>>b>>c>>d>>e>>f>>g>>h ) { Quad p1( a,b ); Quad p2( c,d ); Quad p3( e,f ); Quad p4( g,h ); cout<< fabs ( d(p1.a,p2.a)-d(p3.a,p4.a) )<<endl; } } |
添加回答
舉報
0/150
提交
取消