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

📄 subject_40267.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:40267 发表者:罗兹维尔 发表日期:2003-05-17 10:56:28
<br>主题:钱能老师的这句话啥意思?
<br>内容:#include "iostream.h"<BR><BR>class Student<BR>{<BR>public:<BR>&nbsp;&nbsp;static int noOfStudents;<BR>&nbsp;&nbsp;Student&amp; nextStudent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noOfStudents=30;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return *this;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;//.....<BR>};<BR><BR>int Student::noOfStudents=0;<BR><BR>void fn(Student&amp; s)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;s.nextStudent().noOfStudents&lt;&lt;endl;<BR>}<BR><BR>void main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Student ss;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fn(ss);<BR>}<BR><BR><BR>钱老师的原话:“成员函数nextStudent()实际上未被调用执行。引用静态成员时,C++系统只关心静态成员的类类型。”P-336<BR><BR>//单步跟踪明明到了nextStudent()<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-05-17 11:04:15
<br>内容:我的结果是30<BR>说明执行了的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:罗兹维尔 回复日期:2003-05-17 19:10:14
<br>内容:成员函数nextStudent()实际上未被调用执行<BR><BR>?<BR><BR>up一下
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-05-17 22:44:11
<br>内容:达人入
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-05-18 00:40:19
<br>内容:这可能是钱能在TC上得出的结论。(TC++3.0上确实没有进入函数调用)<BR>其实钱的教材上在该处是自相矛盾的,其原文中函数是这样的:<BR>#include &lt;iostream.h&gt;<BR><BR>class Student<BR>{<BR>public:<BR>&nbsp;&nbsp;static int noOfStudents;<BR>&nbsp;&nbsp;Student&amp; nextStudent()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;noOfStudents++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return *this;<BR>&nbsp;&nbsp;}<BR><BR>//.....<BR>};<BR><BR>int Student::noOfStudents=0;<BR><BR>void fn(Student&amp; s)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;s.nextStudent().noOfStudents&lt;&lt;endl;<BR>}<BR><BR>void main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Student ss;<BR>&nbsp;&nbsp;&nbsp;&nbsp;fn(ss);<BR>}<BR><BR>按钱的意思是不进入该函数,那么输出结果应该为0,但书上在p336上写运行结果为1,这就矛盾了,估计该段是另外的人用vc调试的,而其写书是参照tc。(钱的该教材没有vc对应的实验教材,只有tc下实验教材)。<BR><BR>钱的该教材虽说在国内还算不错,但也有不少错误(像是没有仔细校对),并且感觉在面向对象部分有点乱,把类、构造函数、拷贝构造函数等分成几章来讲,容易引起一些误会。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-05-18 10:51:09
<br>内容:根据ansi c++<BR>结果应该是多少??
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:罗兹维尔 回复日期:2003-05-18 11:37:24
<br>内容:感谢 tjhe! <BR>
<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 + -