subject_26616.htm

来自「一些关于vc的问答」· HTM 代码 · 共 24 行

HTM
24
字号
<p>
序号:26616 发表者:hl211 发表日期:2003-01-03 09:20:17
<br>主题:结构类型可以做数组的基类吗?
<br>内容:代码如下:<BR>IndexName* pIndexName;<BR>CBSR::CBSR(length)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nLength = length;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pIndexName = new IndexName[nLength];<BR>}<BR><BR><BR>struct&nbsp;&nbsp;IndexName<BR>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp; index; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp; attrib; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString&nbsp;&nbsp;LogicName;&nbsp;&nbsp;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2003-01-03 10:26:29
<br>内容:ok
<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>回复者:lin 回复日期:2003-01-03 10:27:48
<br>内容:当然可以<BR><BR>struct&nbsp;&nbsp;IndexName<BR>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp; index; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp; attrib; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString&nbsp;&nbsp;LogicName;&nbsp;&nbsp;<BR>};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //分号不能少<BR><BR>IndexName* pIndexName;<BR>CBSR::CBSR(length)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pIndexName = NULL;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nLength = length;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pIndexName = new IndexName[nLength];<BR>}<BR><BR>析构函数中&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delete pIndexName;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //以防内存泄漏&nbsp;&nbsp;<BR><BR><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>
回复者:hl211 回复日期:2003-01-03 11:00:30
<br>内容:为什么在构造函数里要先:pIndexName=NULL; ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;析构函数最好是:delete []pIndexName;
<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 + =
减小字号Ctrl + -
显示快捷键?