2015-07-01 71 views
0

我正在嘗試使用其他類中的方法結果的值執行操作,我通過引用wingArea值傳遞了值,並且我還嘗試使用方法span()clsSpanCalculation,但Xcode中顯示:「會員功能‘跨度’並不可行:‘這個’參數的類型爲‘常量clsSpanCalculation’,但funtion沒有被標記const的」將方法的引用值傳遞給另一個類

#include <stdio.h> 
#include <cmath> 

class clsSpanCalculation{ 
    float wingArea, aspectRatio; 
public: 
    clsSpanCalculation(){} 
    float get_wingArea(void)const{return wingArea;} 
    void set_wingArea(float Sw){wingArea = Sw;} 
    float get_aspectRatio(void)const{return aspectRatio;} 
    void set_aspectRatio(float AR){aspectRatio = AR;} 

    float span(){ 
     float span; 
     span = sqrt(aspectRatio*wingArea); 
     return span; 
    } 
}; 

class clsChordParameters{ 
    float percentRectArea, percertTrapArea, taperRatio; 
public: 
    float get_percentRectArea(void)const{return percentRectArea;} 
    void set_percentRectArea(float Srect){percentRectArea = Srect;} 
    float get_percentTrapArea(void)const{return percertTrapArea;} 
    void set_percentTrapArea(float Strap){percertTrapArea = Strap;} 
    float get_taperRatio(void)const{return taperRatio;} 
    void set_taperRatio(float lambda){taperRatio = lambda;} 

    float rootChord (const clsSpanCalculation &sC){ 
     float rootChord, lambdaplus; 
     lambdaplus= taperRatio + 1; 
     rootChord = (2*(sC.get_wingArea()*(percentRectArea*(lambdaplus)+(2*percertTrapArea))))/((sC.span()*lambdaplus)/2); 
     return rootChord; 
    } 

    float tipChord (const clsSpanCalculation &sC){ 
     float rootChord, tipChord, lambdaplus; 
     lambdaplus= taperRatio + 1; 
     rootChord = (2*(sC.get_wingArea()*(percentRectArea*(lambdaplus)+(2*percertTrapArea))))/((sC.span()*lambdaplus)/2); 
     tipChord = rootChord*taperRatio; 
     return tipChord; 
    } 
}; 

下面是代碼行的Xcode顯示在其中消息:

rootChord = (2*(sC.get_wingArea()*(percentRectArea*(lambdaplus)+(2*percertTrapArea))))/((sC.span()*lambdaplus)/2); 

我會很感激的幫助。

回答

0

你應該標記span()const像你已經有get_wingArea()get_aspectRatio()有:

float span() const { 
    float span; 
    span = sqrt(aspectRatio*wingArea); 
    return span; 
} 
0

您需要聲明span方法const(換句話說,狀態也不會修改實例,你給它)。

你需要這樣做,因爲rootChordtipChord採取的參數是const clsSpanCalculation &(換句話說,以恆定clsSpanCalculation實例的引用)。

float span() const { 
    ... 
}