当我'一个'对象时问题

时间:2015-07-03 17:44:36

标签: c++ class header cout

当我cout一个函数时,我遇到了一个问题。下一个代码是IDE的位置 给了我错误:

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

clsSpanCalculationclsChordParameters分别在main中定义为span和chord。

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

#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"

1 个答案:

答案 0 :(得分: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对象

     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);