﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-メmarsメ-随笔分类-Single View</title><link>http://www.cppblog.com/jxtgddlt/category/17855.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 02 Oct 2011 04:50:59 GMT</lastBuildDate><pubDate>Sun, 02 Oct 2011 04:50:59 GMT</pubDate><ttl>60</ttl><item><title>静态常成员变量运用</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157338.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Sun, 02 Oct 2011 03:03:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157338.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/157338.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157338.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/157338.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/157338.html</trackback:ping><description><![CDATA[<p>// test.h</p>
<p>class C{<br />public:<br />&nbsp;static const int M;<br />};<br />const int C::M = 12;</p>
<p>// test.cpp<br />#include "stdafx.h"<br />void fun(){<br />&nbsp;cout &lt;&lt; C::M &lt;&lt; endl;<br />}</p>
<p>// main.cpp<br />#include "stdafx.h"<br />#include "test.h"</p>
<p><br />void fun();</p>
<p>int main(){<br />&nbsp;fun();<br />}</p>
<p>// 会出错, 静态常成员变量必须在静态联编的时候解析,而调用fun本就是【另外一个文件中】的函数,因此在link的时候解析,如</p>
<p>果把fun调到main中,则可以正常运行.<br /></p> <img src ="http://www.cppblog.com/jxtgddlt/aggbug/157338.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-10-02 11:03 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157338.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>