满意答案
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分享举报