[英]segmentation fault (core dumped) when I try cout a const char *[i], what is the issue?
[英]Issue when I 'cout' an object
我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);
clsSpanCalculation
和clsChordParameters
類在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"
這段代碼看起來不對
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.