2015-07-03 53 views
0

我遇到了问题,当我cout函数。下面的代码是在IDE 给我的错误:问题当我'cout'一个对象

cout << "La cuerda de raiz tiene valor de: "<< chord.rootChord(const clsSpanCalculation&) 
    << "La cuerda de punta tiene valor de: " << chord.tipChord(clsSpanCalculation &sC); 

clsSpanCalculationclsChordParameters在主跨度为与和弦分别定义的类。

我正在使用头文件,这些类是在那里开发的。 标头是这些的:

#ifndef __IASS_Project__wingSizing__ 
#define __IASS_Project__wingSizing__ 

#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()const{ 
     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 &clsSpanCalculation){ 
     float rootChord, lambdaplus; 
     lambdaplus= taperRatio + 1; 
     rootChord = (2*(clsSpanCalculation.get_wingArea()*(percentRectArea*(lambdaplus)+(2*percertTrapArea))))/((clsSpanCalculation.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; 
    } 
}; 

#endif /* defined(__IASS_Project__wingSizing__) */ 

的IDE给我的错误是这个: expected primary-expression before "const"

+0

也许行号会知道 –

+1

不要使用'const'或'static'传递函数的参数是有用的。您只需要传递变量名称。否则编译器可能会认为你正在声明一个函数。 –

+0

编译器期待表达式。也许你打算使用'chord.rootChord(someObject)'而不是'chord.rootChord(const clsSpanCalculation&)'。 –

回答

0

这个代码看起来错误

cout << "La cuerda de raiz tiene valor de: "<< chord.rootChord(const clsSpanCalculation&) 
<< "La cuerda de punta tiene valor de: " << chord.tipChord(clsSpanCalculation &sC); 

您rootchord()和tipchord()函数期望您传递它的clsSpanCalculation对象insead

 const clsSpanCalculation& // error no object is declared 
    const clsSpanCalculation& sC //error you are passing the address of C but the tipchord() expects the object C not its address 

你想要做的是使这些类的一个对象,并通过再

cout << "La cuerda de raiz tiene valor de: "<< chord.rootChord(clsSpanCalculation C)// you still have to initialise C an sC 
    cout<< "La cuerda de punta tiene valor de: " << chord.tipChord(clsSpanCalculation sC);