📄 subject_15401.htm
字号:
<p>
序号:15401 发表者:最后半年,必须疯狂学习了 发表日期:2002-09-18 09:43:44
<br>主题:一个小小程序的困惑,关于类的构造函数
<br>内容:帮我看一下这个小程序,很短,但编译就是不通过说:“error C2533: 'Goods::Goods' : constructors not allowed a return type” 非常感谢<BR><BR>class Goods<BR>{<BR>public:<BR> Goods(int w); //错误指向这里:(<BR> ~Goods();<BR> int Weight();<BR> static int TotalWeight();<BR>private:<BR> int weight;<BR> static int totalweight;<BR>}<BR><BR>Goods::Goods(int w)<BR>{<BR> weight = w;<BR> totalweight += w;<BR>}<BR><BR>Goods::~Goods()<BR>{<BR> totalweight -= weight;<BR>}<BR><BR>int Goods::Weight()<BR>{<BR> return weight;<BR>}<BR><BR>int Goods::TotalWeight()<BR>{<BR> return totalweight;<BR>}<BR><BR>#include <iostream.h><BR><BR>int Goods::totalweight = 0;<BR><BR>int main()<BR>{<BR> int w;<BR> cin>>w;<BR> Goods g1(w);<BR> cin>>w;<BR> Goods g2(w);<BR> cout<<Goods::TotalWeight()<<endl;<BR> return 0;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:whn 回复日期:2002-09-18 10:00:16
<br>内容:你的类的定义结尾没有“;”号,加上就OK了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:最后半年,必须疯狂学习了 回复日期:2002-09-18 10:17:32
<br>内容:3x.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -