0$房天下问答|C++程序的错误在何处??$https://m.fang.com/ask/ask_573485.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=573485
-
C++程序的错误在何处??
#include <iostream>using namespace std;class Box {public: Box(int w=10,int h=10,int len=10){ height=h; width=w; length=len; } Box( ){height=0; width=0; length=0; }; int volume(){return(height*width*length);} private: int height,width,length; };int main(){ Box box1; cout<<box1.volume()<<endl; Box box2(15); cout<<box2.volume()<<endl; return 0; }
更多
提问者:w503245679
发布于2010-08-17
共1个回答
-
-
-
HANRONG239
丨Lv 0
将第一个构造函数的第一参数(w)的默认值去掉,也就是改成Box(int w,int h=10,int len=10) 就行了.因为你把它的参数都加上默认值的话,当出现Box box1;程式就不知道是应该调用 Box(); 还是调用 Box(int w=10,int h=10,int len=10); 那这样就报错不执行了所以写程式的时候要避免语句的二义性.
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功