📄 subject_26604.htm
字号:
<p>
序号:26604 发表者:松鼠 发表日期:2003-01-03 05:02:08
<br>主题:CList 问题:1,如何作为函数参数传导?
<br>内容:如何把CList作为函数参数传导?<BR><BR>class wordauto<BR>{<BR>public:<BR> CString strModel;<BR> int iRepeat;<BR>public:<BR> wordauto()<BR> {iRepeat=0;}<BR> ~wordauto()<BR> {}<BR>};<BR>上面是我的类定义;<BR>main()<BR>{<BR> CList <wordauto, wordauto> listAuto;<BR> initList(&listAuto); //在这里调用初始化函数<BR>}<BR>尝试1<BR>void InitList(void* plist)<BR>{int i;<BR> CList <wordauto, wordauto> plistAuto;<BR> plistAuto = (CList&)plist; 出错,没有=号运算<BR><BR>}<BR>尝试2<BR>void InitList(CList plist) // 出错,需要定义<BR>//use of class template requires template argument list<BR>{<BR>}<BR>尝试3<BR>修改主函数<BR> initList(&listAuto); //在这里调用初始化函数<BR>为<BR> initList(listAuto); //在这里调用初始化函数<BR>void InitList(CList<wordauto, wordauto> plist)<BR>{<BR>}<BR>出错提示在主函数调用的地方:<BR> error C2664: 'InitList' : cannot convert parameter 1 from 'class CList<class wordauto,class wordauto>' to 'class CList<class wordauto,class wordauto>'<BR>这个最莫名其妙。<BR><BR>问题二:template< class TYPE, class ARG_TYPE ><BR>中的TYPE,ARG_TYPE各是什么意思?<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>
回复者:凯凯 回复日期:2003-01-03 08:19:02
<br>内容:修改尝试1<BR>void InitList(void* plist)<BR>{int i;<BR> CList <wordauto, wordauto> *plistAuto;<BR> plistAuto = (CList <wordauto, wordauto> *)plist;<BR>}<BR><BR>问题二:template< class TYPE, class ARG_TYPE ><BR>中的TYPE,ARG_TYPE各是什么意思?<BR><BR>TYPE是List的元素类型,ARG_TYPE是CList的成员函数的参数类型。一般可以将ARG_TYPE定义为TYPE的引用,这样效率会高一些。你的定义可以改为<BR>CList <wordauto, wordauto&>
<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>回复者:bb 回复日期:2003-01-03 16:11:32
<br>内容:1.<BR>typdef CList<wordauto, wordauto&> CMyList;<BR><BR>void InitList(CMyList & list)<BR>{<BR> ......<BR>};<BR><BR>2. same as 凯凯 <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 + -