亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

您好,請問下面關于調用的表達式前的括號必須具有(指針)函數類型,錯在哪?

您好,請問下面關于調用的表達式前的括號必須具有(指針)函數類型,錯在哪?

白衣染霜花 2021-12-08 15:11:03
#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])();
}

查看完整回答
反對 回復 2021-12-12
?
嗶嗶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同名,不可見??筛臑閐ddouble d( point &a,point &b )return sqrtpow( (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;   }}



查看完整回答
反對 回復 2021-12-12
  • 2 回答
  • 0 關注
  • 443 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號