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

📄 subject_26322.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:26322 发表者:white 发表日期:2002-12-31 09:37:29
<br>主题:求救高手如何理解这里的 copy函数?不胜感激
<br>内容:有如下例程定义一个点类<BR>class DPOINT<BR>{<BR>&nbsp;&nbsp; public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;double x;<BR>&nbsp;&nbsp;&nbsp;&nbsp;double y;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; CArray&lt;int,int&gt; Lines;<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT(const DPOINT&amp; point)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lines.Copy(point.Lines);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT()<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lines.FreeExtra();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;operator=(const DPOINT&amp; point)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lines.Copy(point.Lines);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;void FreeAll()<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Lines.RemoveAll();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;};<BR><BR>本类中<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT(const DPOINT&amp; point)<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT()<BR>两个同名构造函数是函数的重载吗?<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT(const DPOINT&amp; point)和&nbsp;&nbsp;&nbsp;&nbsp;operator=(const DPOINT&amp; 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&amp; point)&nbsp;&nbsp;//拷贝构造函数<BR>&nbsp;&nbsp;&nbsp;&nbsp;DPOINT()&nbsp;&nbsp; //构造函数<BR>是构造函数重载,适应不同方式的对象构造<BR>DPOINT(const DPOINT&amp; point)和&nbsp;&nbsp;&nbsp;&nbsp;operator=(const DPOINT&amp; point) 中copy 是CArray中的成员函数void Copy( const CArray&amp; 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&amp; point) 这个函数干了什么? 是定义了“=”的操作吗?<BR>“DPOINT(const DPOINT&amp; point)&nbsp;&nbsp;//拷贝构造函数"&nbsp;&nbsp;什么是拷贝构造函数啊?&nbsp;&nbsp;有何用?<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 + -