📄 subject_26322.htm
字号:
<p>
序号:26322 发表者:white 发表日期:2002-12-31 09:37:29
<br>主题:求救高手如何理解这里的 copy函数?不胜感激
<br>内容:有如下例程定义一个点类<BR>class DPOINT<BR>{<BR> public:<BR> double x;<BR> double y;<BR> <BR> CArray<int,int> Lines;<BR> DPOINT(const DPOINT& point)<BR> {<BR> Lines.Copy(point.Lines);<BR> }<BR> DPOINT()<BR> {<BR> Lines.FreeExtra();<BR> }<BR> operator=(const DPOINT& point)<BR> {<BR> Lines.Copy(point.Lines);<BR> }<BR> void FreeAll()<BR> {<BR> Lines.RemoveAll();<BR> }<BR> };<BR><BR>本类中<BR> DPOINT(const DPOINT& point)<BR> DPOINT()<BR>两个同名构造函数是函数的重载吗?<BR> DPOINT(const DPOINT& point)和 operator=(const DPOINT& point) 中copy 是什么意思?<BR><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>
<font color=red>答案被接受</font><br>回复者:tigersky2000 回复日期:2002-12-31 09:42:34
<br>内容:是重载函数!<BR><BR>const的意思是 point所指的值在这个函数中是不可以更改的,是常量
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tjhe 回复日期:2002-12-31 09:51:16
<br>内容:DPOINT(const DPOINT& point) //拷贝构造函数<BR> DPOINT() //构造函数<BR>是构造函数重载,适应不同方式的对象构造<BR>DPOINT(const DPOINT& point)和 operator=(const DPOINT& point) 中copy 是CArray中的成员函数void Copy( const CArray& src );
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:white 回复日期:2002-12-31 11:31:42
<br>内容:非常谢谢两位高手,但我还 不明白operator=(const DPOINT& point) 这个函数干了什么? 是定义了“=”的操作吗?<BR>“DPOINT(const DPOINT& point) //拷贝构造函数" 什么是拷贝构造函数啊? 有何用?<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>
回复者:tigersky2000 回复日期:2002-12-31 12:09:03
<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 + -