java定义一个盒子类box_定义一个Box(盒子)类,在该类定义中包括数据成员: length(长),width(宽)和height(...

满意答案

szkcl

2014.05.28

采纳率:54%    等级:8

已帮助:964人

1234567891011121314151617181920212223242526272829#include using namespace std; class Box {    float length, width, height;public:    Box(float l, float w, float h);    float GetVolume() const;}; Box::Box(float l = 1, float w = 1, float h = 1)     : length(l), width(w), height(h) {} float Box::GetVolume() const {    return height * width * length;} int main(){    Box b1, b2(2, 3, 4);    float v1, v2;    v1 = b1.GetVolume();    v2 = b2.GetVolume();    if (v1>v2)        cout <

这行有错哎~error C2512: 'Box' : no appropriate default constructor available

怎么改呢???

追答:1234567891011121314151617181920212223242526272829303132#include using namespace std; class Box {    float length, width, height;public:    Box();    Box(float l, float w, float h);    float GetVolume() const;}; Box::Box() : length(1), width(1), height(1) {} Box::Box(float l, float w, float h): length(l), width(w), height(h) {} float Box::GetVolume() const {    return height * width * length;} int main(){    Box b1, b2(2, 3, 4);    float v1, v2;    v1 = b1.GetVolume();    v2 = b2.GetVolume();    if (v1>v2)        cout <

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值