⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_15401.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:15401 发表者:最后半年,必须疯狂学习了 发表日期:2002-09-18 09:43:44
<br>主题:一个小小程序的困惑,关于类的构造函数
<br>内容:帮我看一下这个小程序,很短,但编译就是不通过说:“error C2533: 'Goods::Goods' : constructors not allowed a return type”&nbsp;&nbsp;非常感谢<BR><BR>class Goods<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;Goods(int w);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//错误指向这里:(<BR>&nbsp;&nbsp;&nbsp;&nbsp;~Goods();<BR>&nbsp;&nbsp;&nbsp;&nbsp;int Weight();<BR>&nbsp;&nbsp;&nbsp;&nbsp;static int TotalWeight();<BR>private:<BR>&nbsp;&nbsp;&nbsp;&nbsp;int weight;<BR>&nbsp;&nbsp;&nbsp;&nbsp;static int totalweight;<BR>}<BR><BR>Goods::Goods(int w)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;weight = w;<BR>&nbsp;&nbsp;&nbsp;&nbsp;totalweight += w;<BR>}<BR><BR>Goods::~Goods()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;totalweight -= weight;<BR>}<BR><BR>int Goods::Weight()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;return weight;<BR>}<BR><BR>int Goods::TotalWeight()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;return totalweight;<BR>}<BR><BR>#include &lt;iostream.h&gt;<BR><BR>int Goods::totalweight = 0;<BR><BR>int main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int w;<BR>&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;w;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Goods g1(w);<BR>&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;w;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Goods g2(w);<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;Goods::TotalWeight()&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;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 + -