0
我只是在嘗試一個計算立方體體積的簡單程序。我已經在main中聲明瞭這個對象,當我嘗試訪問帶有用戶輸入參數的類的函數時,它顯示一個錯誤:請求'vol'中的成員'volume cube',它是非類類型'Vellimi()'。爲什麼會發生?錯誤:請求非類別成員
#include <iostream>
using namespace std;
class Vellimi {
private:
double width;
double height;
double length;
public:
Vellimi(double,double,double);
double volume_cube (double width,double height,double length)
{
return width*height*length;
}
};
Vellimi::Vellimi(double a,double b,double c){
width=a;
height=b;
length=c;
}
int main()
{
double x,y,z;
Vellimi vol();
cout<<"Input the width : "<<endl;
cin>>x;
cout<<"Input the height : "<<endl;
cin>>y;
cout<<"Input the length : "<<endl;
cin>>z;
cout<<"The volume is "<<vol.volume_cube(x,y,z)<<endl;
return 0;
}
_'Vellimi體積();'_其實聲明的函數。只要寫「Vellimi vol;'。 –
@πάνταῥεῖ我試過了,它仍然顯示錯誤 –
對不起,我應該寫'Vellimi vol(0.0,0.0,0.0);'因爲'Vellimi'沒有默認的構造函數。你仍然有一個函數聲明,因此會產生令人困惑的錯誤信息。 –