注册 登录
编程论坛 C++教室

各位高手帮忙看看它错在哪

张堪绘 发布于 2013-04-20 00:04, 406 次点击
#include<iostream>
using namespace std;
#define PI 3.14
class cylinder{
public:
    cylinder(double r,double h);
    double vol();
private:
    double radius;
    double height;
};
cylinder::cylinder(double r,double h);
{radius=r;height=h;}
double cylinder::vol()
{cout<<PI*radius*radius*height<<endl;}
int main()
{ int n;cylinder voln;
cout<<"The volume of cylimder is"<<voln.vol()<<endl;return 0;}
3 回复
#2
peach54602013-04-20 07:16
瞟了一眼,好像还好啊...
#3
锋了2013-04-20 12:04
粗心而已,这里多来个分号
cylinder::cylinder(double r,double h);
  {radius=r;height=h;}

然后就是你cylinder类里面没有默认的构造函数,原来默认的因为你的显示定义来来cylinder(double r,double h)被屏蔽了吧,
在声明这里时应该会出错吧
int n;cylinder voln


[ 本帖最后由 锋了 于 2013-4-20 12:06 编辑 ]
#4
机器王者2013-04-20 14:50
cylinder函数都没有值,不能计算啊,应定义析构函数
1