📄 subject_36261.htm
字号:
<p>
序号:36261 发表者:IEEE 发表日期:2003-04-13 20:40:59
<br>主题:请指教!
<br>内容:#include "iostream.h"<BR>class base<BR>{ <BR> int a;<BR>public:<BR> base(int x) { a=x; }<BR> void show() { cout<<a<<endl; }<BR>};<BR><BR>class derived : public base<BR>{ <BR> int b;<BR>public:<BR> derived(int x,int y) : base(y) { b=x; }<BR> void show() { cout<<b<<endl; }<BR>};<BR><BR>void main()<BR>{ <BR> derived obj(10,20);<BR> obj.show(); <BR>}<BR>请问main()函数中 obj.show() 语句执行时为什么没有二义性(vc中编译通过! 输出结果为:10)?<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>回复者:小年 回复日期:2003-04-13 20:56:51
<br>内容:函数重载,为什么会有二义性<BR>分别编译为:<BR>void show(class base *this) { cout<<a<<endl; }<BR><BR>void show(class derived *this) { cout<<a<<endl; }<BR><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 + -