数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 5486|回复: 4

[求助]C++程序求助

[复制链接]
发表于 2006-9-24 02:12:38 | 显示全部楼层 |阅读模式
<p>有一处错误是:'employer::employer' : constructors not allowed a return type</p><p>那位大虾帮忙看一下:</p><p>源代码如下:</p><p>#include&lt;iostream&gt;<br/>#include&lt;cmath&gt;<br/>using namespace std;<br/>class employee<br/>{<br/>&nbsp; public:<br/>&nbsp;&nbsp; employee();<br/>&nbsp; ~employee();<br/>&nbsp;&nbsp; employee(employee &amp;e);<br/>&nbsp;&nbsp; void Add();<br/>&nbsp;&nbsp; void Show();<br/>&nbsp;&nbsp; private:<br/>&nbsp;&nbsp; int No;<br/>&nbsp;&nbsp; char sex;<br/>&nbsp;&nbsp; float birth;<br/>&nbsp;&nbsp; float idNo;<br/>};<br/>employee::employee(employee &amp;e)<br/>{ <br/>&nbsp; No=e.No;<br/>&nbsp; sex=e.sex;<br/>&nbsp; birth=e.birth;<br/>&nbsp; idNo=e.idNo;<br/>&nbsp; cout&lt;&lt;"employee拷贝数据被调用"&lt;&lt;endl;<br/>}<br/>class employer<br/>{<br/>&nbsp; public:<br/>&nbsp; employer(employee xe1,employee xe2);<br/>&nbsp; employer(employer &amp;);<br/>&nbsp; private:<br/>&nbsp; employee e1,e2;<br/>}<br/>employer::employer(employee xe1,employee xe2)<br/>:e1(xe1),e2(xe2)<br/>{ <br/>&nbsp;&nbsp; cout&lt;&lt;"employer构造函数被调用 "&lt;&lt;endl;<br/>&nbsp;&nbsp;&nbsp; e1.Add();<br/>&nbsp;&nbsp;&nbsp; e1.Show();<br/>}<br/>employer::employer(employer &amp;em):e1(em.e1),e2(em.e2)<br/>{<br/>&nbsp;cout&lt;&lt;"employer拷贝构造函数被调用"&lt;&lt;endl;<br/>}<br/>inline void employee::Add()<br/>{<br/>&nbsp;cout&lt;&lt;"输入增加的职工信息"&lt;&lt;endl;<br/>&nbsp;cin&gt;&gt;No&gt;&gt;sex&gt;&gt;birth&gt;&gt;idNo;<br/>}<br/>inline void employee::Show()<br/>{<br/>&nbsp;cout&lt;&lt;"职工号:"&lt;&lt;No&lt;&lt;"性别:"&lt;&lt;sex&lt;&lt;"出生日期:"&lt;&lt;birth&lt;&lt;"身份证号:"&lt;&lt;idNo;<br/>}<br/>&nbsp;void main()<br/>{<br/>&nbsp;employee e1,e2;<br/>&nbsp;e1.Add();<br/>&nbsp;e1.Show();<br/>&nbsp;getchar();<br/>}<br/></p>
发表于 2006-9-27 22:41:52 | 显示全部楼层
<p>像这样才对</p><p>#include&lt;iostream&gt;<br/>#include&lt;cmath&gt;<br/>using namespace std;<br/>class employee<br/>{<br/>&nbsp; public:<br/>&nbsp;&nbsp; employee();<br/>&nbsp; ~employee();<br/>&nbsp;&nbsp; employee(employee &amp;e);<br/>&nbsp;&nbsp; void Add();<br/>&nbsp;&nbsp; void Show();<br/>&nbsp;&nbsp; private:<br/>&nbsp;&nbsp; int No;<br/>&nbsp;&nbsp; char sex;<br/>&nbsp;&nbsp; float birth;<br/>&nbsp;&nbsp; float idNo;<br/>};</p><p>employee::employee()<br/>{<br/>}</p><p>employee::~employee()<br/>{<br/>}</p><p>employee::employee(employee &amp;e)<br/>{ <br/>&nbsp; No=e.No;<br/>&nbsp; sex=e.sex;<br/>&nbsp; birth=e.birth;<br/>&nbsp; idNo=e.idNo;<br/>&nbsp; cout&lt;&lt;"employee&iquest;&frac12;±&acute;&Ecirc;&yacute;&frac34;&Yacute;±&raquo;&micro;÷&Oacute;&Atilde;"&lt;&lt;endl;<br/>}<br/>class employer<br/>{<br/>&nbsp; public:<br/>&nbsp; employer(employee xe1,employee xe2);<br/>&nbsp; employer(employer &amp;);<br/>&nbsp; private:<br/>&nbsp; employee e1,e2;<br/>};</p><p>employer::employer(employee xe1,employee xe2)<br/>{ <br/>&nbsp;&nbsp; cout&lt;&lt;"employer&sup1;&sup1;&Ocirc;ì&ordm;&macr;&Ecirc;&yacute;±&raquo;&micro;÷&Oacute;&Atilde; "&lt;&lt;endl;<br/>&nbsp;&nbsp;&nbsp; e1.Add();<br/>&nbsp;&nbsp;&nbsp; e1.Show();<br/>}<br/>employer::employer(employer &amp;em):e1(em.e1),e2(em.e2)<br/>{<br/>&nbsp;cout&lt;&lt;"employer&iquest;&frac12;±&acute;&sup1;&sup1;&Ocirc;ì&ordm;&macr;&Ecirc;&yacute;±&raquo;&micro;÷&Oacute;&Atilde;"&lt;&lt;endl;<br/>}<br/>inline void employee::Add()<br/>{<br/>&nbsp;cout&lt;&lt;"&Ecirc;&auml;&Egrave;&euml;&Ocirc;&ouml;&frac14;&Oacute;&micro;&Auml;&Ouml;°&sup1;¤&ETH;&Aring;&Iuml;&cent;"&lt;&lt;endl;<br/>&nbsp;cin&gt;&gt;No&gt;&gt;sex&gt;&gt;birth&gt;&gt;idNo;<br/>}<br/>inline void employee::Show()<br/>{<br/>&nbsp;cout&lt;&lt;"&Ouml;°&sup1;¤&ordm;&Aring;:"&lt;&lt;No&lt;&lt;"&ETH;&Ocirc;±&eth;:"&lt;&lt;sex&lt;&lt;"&sup3;&ouml;&Eacute;ú&Egrave;&Otilde;&AElig;&Uacute;:"&lt;&lt;birth&lt;&lt;"&Eacute;í·&Yacute;&Ouml;¤&ordm;&Aring;:"&lt;&lt;idNo;<br/>}<br/>&nbsp;void main()<br/>{<br/>&nbsp;employee e1,e2;<br/>&nbsp;e1.Add();<br/>&nbsp;e1.Show();<br/>&nbsp;getchar();<br/>}</p><p></p>
发表于 2006-9-27 22:26:19 | 显示全部楼层
<p>再加一个空的构造函数就好了</p>
发表于 2006-9-27 22:40:31 | 显示全部楼层
<p>还有 employee的西构函数呢</p><p></p>
发表于 2006-9-27 22:41:18 | 显示全部楼层
<p>class employer<br/>{<br/>&nbsp; public:<br/>&nbsp; employer(employee xe1,employee xe2);<br/>&nbsp; employer(employer &amp;);<br/>&nbsp; private:<br/>&nbsp; employee e1,e2;<br/>}<br/>缺“;”</p><p>语法错误</p>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-26 22:32 , Processed in 0.057794 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表