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

📄 subject_55755.htm

📁 vc
💻 HTM
字号:
<p>
序号:55755 发表者:James 发表日期:2003-10-12 20:22:23
<br>主题:请高手解释一下!
<br>内容:在学习typedef的用法的时候,MSDN中有这样一个示例:<BR>。。。<BR>typedef int (*funcptr)();&nbsp;&nbsp;<BR>funcptr table[10];<BR>。。。<BR>以上的定义等价于:<BR>int (*table[10])();<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>回复者:xiongli 回复日期:2003-10-12 20:40:20
<br>内容:typedef是给一个变量类型其一个别名<BR>这里的typedef int (*funcptr)();<BR>就是把int (*)()这个函数指针类型起了一个别名叫做funcptr<BR>后面用funcptr table[10];这样定义table数组,就是等于用int(*)()定义数组
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:提刀入人间 回复日期:2003-10-12 21:31:54
<br>内容:看来我得 基础好差啊.<BR>得 好好 补补了! <BR>typedef int (*funcptr)();<BR>解释成就是把int (*)()这个函数指针类型起了一个别名叫做funcptr.<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>
回复者:xiongli 回复日期:2003-10-12 22:37:10
<br>内容:typedef<BR>typedef type-declaration synonym;<BR><BR>The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition.<BR><BR>A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types.<BR><BR>Example<BR><BR>// Example of the typedef keyword<BR>typedef unsigned long ulong;<BR><BR>ulong ul;&nbsp;&nbsp;&nbsp;&nbsp; // Equivalent to &#34;unsigned long ul;&#34;<BR><BR>typedef struct mystructtag<BR>{<BR>&nbsp;&nbsp; int&nbsp;&nbsp; i;<BR>&nbsp;&nbsp; float f;<BR>&nbsp;&nbsp; char&nbsp;&nbsp;c;<BR>} mystruct;<BR><BR>mystruct ms;&nbsp;&nbsp; // Equivalent to &#34;struct mystructtag ms;&#34;<BR><BR>typedef int (*funcptr)();&nbsp;&nbsp;// funcptr is synonym for &#34;pointer<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;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;to function returning int&#34;<BR><BR>funcptr table[10];&nbsp;&nbsp; // Equivalent to &#34;int (*table[10])();&#34;<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>
回复者:James 回复日期:2003-10-20 17:59:38
<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 + -