请高手帮我看看这个程序哪有问题?

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:24:34
#include<iostream>
using namespace std;
class time
{
public:
double volum(double length,double width,double height);
double length;
double width;
double height;
time(double x,double y,double z):length(x),width(y),height(z){}
};
double time::volum(double length,double width,double height)
{
return(length*width*height);

}
int main()
{
time t1;
t1(10,10,10);
cin>>t1.length>>t1.width>>t1.height;
volum(t1.length,t1.width,t1.height);
return 0;
}
补充:在倒数第三行代码的volum前加上"cout<<"以输出体积。 该程序编译时出现“c:\documents and settings\administrator\桌面\1\cpp2.cpp(19) : error C2512: 'time' : no appropriate default constructor available
c:\documents and settings\administrator\桌面\1\cpp2.cpp(20) : error C2064: term does not evaluate to a function
c:\documents and settings\administ

我给你改了改,这样应该就可以编译了

#include<iostream>
using namespace std;
class time
{
public:
double volum();
double length;
double width;
double height;
time(double x,double y,double z):length(x),width(y),height(z){}
};
double time::volum()
{
return(length*width*height);
}
int main()
{
time t1(10,10,10);
cin>>t1.length>>t1.width>>t1.height;
cout<<t1.volum();
return 0;
}

time t1;
这里需要不带参数的构造函数, 而你没提供