您好,请问下面关于调用的表达式前的括号必须具有(指针)函数类型,错在哪?

#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;
}
}

错在哪?

白衣染霜花
浏览 388回答 2
2回答

蓝山帝景

没试过,但你想一下调用一个类的局部函数的形式应该是 (对象).(函数)()的形式,而你的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

#include<iostream>using&nbsp;namespace&nbsp;std;#include<cmath>struct&nbsp;point{&nbsp;&nbsp;double&nbsp;x;&nbsp;&nbsp;&nbsp;double&nbsp;y;};class&nbsp;Quad{&nbsp;&nbsp;&nbsp;public:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quad(&nbsp;int&nbsp;t1,int&nbsp;t2&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;a.x=t1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a.y=t2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;point&nbsp;a;};//&nbsp;函数名为d跟main里面的d同名,不可见。可改为dddouble&nbsp;d(&nbsp;point&nbsp;&a,point&nbsp;&b&nbsp;){&nbsp;return&nbsp;sqrt(&nbsp;pow(&nbsp;(a.x-b.x),2)&nbsp;-&nbsp;pow(&nbsp;a.y-b.y,2&nbsp;)&nbsp;);&nbsp;}int&nbsp;main(){&nbsp;&nbsp;double&nbsp;a,b,c,d,e,f,g,h;&nbsp;//&nbsp;变量d跟函数d同名。请改其中之一&nbsp;&nbsp;&nbsp;while(&nbsp;cin>>a>>b>>c>>d>>e>>f>>g>>h&nbsp;)&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;Quad&nbsp;p1(&nbsp;a,b&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quad&nbsp;p2(&nbsp;c,d&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quad&nbsp;p3(&nbsp;e,f&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quad&nbsp;p4(&nbsp;g,h&nbsp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout<<fabs(&nbsp;d(p1.a,p2.a)-d(p3.a,p4.a)&nbsp;)<<endl;&nbsp;&nbsp;&nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP