📄 subject_26064.htm
字号:
<p>
序号:26064 发表者:titany 发表日期:2002-12-28 13:20:44
<br>主题:关于外部变量extern的问题
<br>内容:inking...<BR>Text4.obj : error LNK2001: unresolved external symbol "int x" (?x@@3HA)<BR>Text4.obj : error LNK2001: unresolved external symbol "int y" (?y@@3HA)<BR>Debug/Text4.exe : fatal error LNK1120: 2 unresolved externals<BR>Error executing link.exe.<BR><BR>Text4.exe - 3 error(s), 0 warning(s)<BR>编译可通过,但链接出错,请问怎么解决这个问题<BR>extern int x,y;<BR>#include <iostream.h><BR>int main()<BR>{<BR> void gx(void),gy(void);<BR> cout<<"1:x="<<x<<"\ty="<<y<<endl;<BR> y=246;<BR> gx();<BR> gy();<BR> return 0;<BR>}<BR>void gx()<BR>{<BR> extern int x,y;<BR> x=135;<BR> cout<<"2:x="<<x<<"\ty="<<y<<endl;<BR>}<BR>void gy()<BR>{<BR> cout<<"3:x="<<x<<"\ty="<<y<<endl;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:ohye212 回复日期:2002-12-28 13:28:17
<br>内容:你的int x;<BR> int y;<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>
回复者:PLB 回复日期:2002-12-28 14:11:05
<br>内容:定义的时候不要加extern
<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>回复者:军人 回复日期:2002-12-28 14:36:16
<br>内容:楼上兄弟说的没错,外部变量在你声明时不要加extern,而只有当你要使用时才通过加extern来表示这是一个外部变量。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:titany 回复日期:2002-12-30 11:19:21
<br>内容:这是不是BC和VC的区别之处?书上说是在bc是调试通过的,我现在用的是vc<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>
回复者:军人 回复日期:2002-12-30 11:54:25
<br>内容:老兄,我试了一下你的程序,只要去掉前面的extern就行啦。如下<BR>int x,y;<BR>#include <iostream.h><BR>int main()<BR>{<BR> void gx(void),gy(void);<BR> cout<<"1:x="<<x<<"\ty="<<y<<endl;<BR> y=246;<BR> gx();<BR> gy();<BR> return 0;<BR>}<BR>void gx()<BR>{<BR> extern int x,y;<BR> x=135;<BR> cout<<"2:x="<<x<<"\ty="<<y<<endl;<BR>}<BR>void gy()<BR>{<BR> cout<<"3:x="<<x<<"\ty="<<y<<endl;<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 + -