📄 subject_60874.htm
字号:
<p>
序号:60874 发表者:bluesealam 发表日期:2003-11-16 10:52:10
<br>主题:字符串在函数中的引用该如何转换?
<br>内容:void gacawl(char &);<BR>char gw[16];<BR>gacaw(gw[16]);<BR>void gacaw(char &p)<BR>{<BR> PIP_ADAPTER_INFO pinfo=NULL;<BR> unsigned long len=0;<BR> ::GetAdaptersInfo(pinfo,&len);<BR> p=pinfo->GatewayList.IpAddress.String;<--错误指向这里<BR>}<BR>编译的时候怎么总提示这个错误:<BR>cannot convert from 'char [16]' to 'char'<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>回复者:hurtmanzc 回复日期:2003-11-16 11:23:08
<br>内容:用指针作参数<BR>void gacawl(char*);<BR>char gw[16];<BR>gacaw(gw);<BR>void gacaw(char *p)<BR>{<BR> PIP_ADAPTER_INFO pinfo=NULL;<BR> unsigned long len=0;<BR> ::GetAdaptersInfo(pinfo,&len);<BR> p=pinfo->GatewayList.IpAddress.String;//<--错误指向这里<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>
回复者:oldjacky 回复日期:2003-11-16 14:31:40
<br>内容: 这是一个指针的引用,如果你非得使用引用的方式的话,可以用下面的方法(其实这样比较烦琐的,在这里还是用指针明确一点),由于一个引用在整个程序中只能被引用一次,它不像指针可以改变它里面的地址值,重定向到另一个对象/变量/常量。<BR> 在这里你所要做的是定义一个引用指向一串字符,但你有没有想过,字符串其实就是字符组成,char指针或数据它有一个自动阅读下一个单元的功能,而引用只能引用数组中某一个单元,所以会出错,char&p=gw;这样gw中20个数据只能有一个可以给p,究竟是哪一个单元给p呢?程序不能进行判断,致出错。<BR>void gacawl(char &);<BR>char gw[16];<BR>gacaw(gw[16]);<BR>void gacaw(char *&p)<BR>{<BR> PIP_ADAPTER_INFO pinfo=NULL;<BR> unsigned long len=0;<BR> ::GetAdaptersInfo(pinfo,&len);<BR> char *getTemp;<BR> getTemp=pinfo->GatewayList.IpAddress.String;<BR> p=getTemp;<--错误指向这里<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 + -