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

📄 subject_64365.htm

📁 vc
💻 HTM
字号:
<p>
序号:64365 发表者:由零开始 发表日期:2003-12-10 12:17:36
<br>主题:static成员变量的赋值
<br>内容://screen.h<BR>#include &lt;string&gt;<BR>using namespace std;<BR><BR>class Screen<BR>{<BR><BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;void home() { _cursor = 0;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;void move( int, int );<BR>&nbsp;&nbsp;&nbsp;&nbsp;char get() { return _screen[_cursor];}<BR>&nbsp;&nbsp;&nbsp;&nbsp;char get( int,int);<BR>private:<BR>&nbsp;&nbsp;&nbsp;&nbsp;string _screen;<BR>&nbsp;&nbsp;&nbsp;&nbsp;string::size_type _cursor;<BR>//&nbsp;&nbsp;&nbsp;&nbsp;short _height;<BR>//&nbsp;&nbsp;&nbsp;&nbsp;short _width;<BR>&nbsp;&nbsp;&nbsp;&nbsp;static const int _height = 24;&nbsp;&nbsp;//-------- 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;static const int _width = 80;&nbsp;&nbsp; //-------- 2<BR>};<BR><BR>//screen.cpp<BR>#include &#34;screen.h&#34;<BR><BR>int main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Screen abc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;system(&#34;pause&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR><BR>1和2处在vc下出错,在dev下pass.如果想在vc下ok, 如何修改?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:倪璐舟 回复日期:2003-12-10 13:15:50
<br>内容:静态变量在类里面声明后,在外面还要定义一下,在外面加两行 static const int _height ;static const int _width ;应该可以了
<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-12-10 13:24:20
<br>内容:&lt;BLOCKQUOTE&gt;引用“第1楼”所言<BR>&lt;Q&gt;静态变量在类里面声明后,在外面还要定义一下&lt;/Q&gt;&lt;/BLOCKQUOTE&gt;<BR><BR>这是c++的标准吗?上面的程序在dev-c下却是通过的。<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>
回复者:倪璐舟 回复日期:2003-12-10 13:37:28
<br>内容: const int screen::_height ; <BR> const int screen::_width;<BR>你加这个把,再类外面肯定要定义的,我刚翻书看过<BR>2003-12-10 13:38:41

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -