<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 8.11 &#8212; Static member variables</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/811-static-member-variables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/</link>
	<description></description>
	<lastBuildDate>Tue, 09 Mar 2010 02:02:41 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: heya</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-74698</link>
		<dc:creator>heya</dc:creator>
		<pubDate>Wed, 23 Dec 2009 02:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-74698</guid>
		<description>small typo:
In fact, s_nValue exists even if there are no objects of the class have been instantiated!
should be
In fact, s_nValue exists even if no objects of the class have been instantiated!

or, you know, something similar. Nice website, I&#039;ve learnt more here than in my university. They insist on &quot;taking it slow&quot; by teaching nothing more complex than pointers. You know, really incredibly abstract things like object oriented programming that only gurus and wise old men can know. I&#039;m lucky they aren&#039;t trying to ease me into c by teaching me pascal first (they did that up to this year).</description>
		<content:encoded><![CDATA[<p>small typo:<br />
In fact, s_nValue exists even if there are no objects of the class have been instantiated!<br />
should be<br />
In fact, s_nValue exists even if no objects of the class have been instantiated!</p>
<p>or, you know, something similar. Nice website, I&#8217;ve learnt more here than in my university. They insist on &#8220;taking it slow&#8221; by teaching nothing more complex than pointers. You know, really incredibly abstract things like object oriented programming that only gurus and wise old men can know. I&#8217;m lucky they aren&#8217;t trying to ease me into c by teaching me pascal first (they did that up to this year).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sachin</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-71467</link>
		<dc:creator>sachin</dc:creator>
		<pubDate>Mon, 02 Nov 2009 12:02:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-71467</guid>
		<description>yeah, even i think so.
AFAIK static classes will be in Java, not in C++, right?</description>
		<content:encoded><![CDATA[<p>yeah, even i think so.<br />
AFAIK static classes will be in Java, not in C++, right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Topjob</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-66832</link>
		<dc:creator>Topjob</dc:creator>
		<pubDate>Sat, 22 Aug 2009 00:55:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-66832</guid>
		<description>Alex, then what did you mean by:
  
&quot;In the absense of an initializing line, C++ will initialize the value to 0.&quot;?</description>
		<content:encoded><![CDATA[<p>Alex, then what did you mean by:</p>
<p>&#8220;In the absense of an initializing line, C++ will initialize the value to 0.&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: baldo</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-66549</link>
		<dc:creator>baldo</dc:creator>
		<pubDate>Tue, 18 Aug 2009 13:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-66549</guid>
		<description>Alex, I think you made a typo here: &quot;C++ introduces two new uses for the static keyword when applied to classes: static member variables, and static member &lt;strong&gt;classes&lt;/strong&gt;.&quot; I think it is static member &lt;strong&gt;functions&lt;/strong&gt; not &lt;strong&gt;classes&lt;/strong&gt;.</description>
		<content:encoded><![CDATA[<p>Alex, I think you made a typo here: &#8220;C++ introduces two new uses for the static keyword when applied to classes: static member variables, and static member <strong>classes</strong>.&#8221; I think it is static member <strong>functions</strong> not <strong>classes</strong>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zelbacsi</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-59955</link>
		<dc:creator>Zelbacsi</dc:creator>
		<pubDate>Mon, 04 May 2009 10:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-59955</guid>
		<description>I&#039;m so confused right now ...

In 4.2 you said not to use global variables:

&lt;i&gt;&quot;2) To hold data that needs to be used by the entire program (eg. configuration settings).&quot;&lt;/i&gt;
(that&#039;s what i&#039;d need to do)

&lt;i&gt;&quot;there are better ways to do #2 (eg. static classes).&quot;&lt;/i&gt;
Still, I didn&#039;t found anything like &quot;static classes&quot; in later lessons. Did you mean this? (classes with static members) Although, from your examples, &#039;static&#039; seems to serve an entirely different purpose in classes, then the one mentioned above in &lt;i&gt;2)&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;m so confused right now &#8230;</p>
<p>In 4.2 you said not to use global variables:</p>
<p><i>&#8220;2) To hold data that needs to be used by the entire program (eg. configuration settings).&#8221;</i><br />
(that&#8217;s what i&#8217;d need to do)</p>
<p><i>&#8220;there are better ways to do #2 (eg. static classes).&#8221;</i><br />
Still, I didn&#8217;t found anything like &#8220;static classes&#8221; in later lessons. Did you mean this? (classes with static members) Although, from your examples, &#8217;static&#8217; seems to serve an entirely different purpose in classes, then the one mentioned above in <i>2)</i></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-59779</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 06:14:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-59779</guid>
		<description>The function returns s_nID++;  This means the value of s_nID is set aside, then s_nID is incremented, then the old value of s_nID is returned.

For example, let&#039;s say s_nID is 0.  The value 0 is copied into a temp variable.  s_nID is incremented to 1.  Then the value 0 is returned.

All of this happens transparently when you use the postfix ++ operator.  That&#039;s why using the prefix ++ operator can be more efficient.</description>
		<content:encoded><![CDATA[<p>The function returns s_nID++;  This means the value of s_nID is set aside, then s_nID is incremented, then the old value of s_nID is returned.</p>
<p>For example, let&#8217;s say s_nID is 0.  The value 0 is copied into a temp variable.  s_nID is incremented to 1.  Then the value 0 is returned.</p>
<p>All of this happens transparently when you use the postfix ++ operator.  That&#8217;s why using the prefix ++ operator can be more efficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-59723</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 02 May 2009 03:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-59723</guid>
		<description>Static member variables always need to be defined in the code file.  The fact that

&lt;pre&gt;
int Something::s_nValue
&lt;/pre&gt;

happened to evaluate to 0 was probably circumstantial in the same way that

&lt;pre&gt;
int nX;
&lt;/pre&gt;

will probably be 0, but it&#039;s not guaranteed.</description>
		<content:encoded><![CDATA[<p>Static member variables always need to be defined in the code file.  The fact that</p>
<pre>
int Something::s_nValue
</pre>
<p>happened to evaluate to 0 was probably circumstantial in the same way that</p>
<pre>
int nX;
</pre>
<p>will probably be 0, but it&#8217;s not guaranteed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cammy</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-59689</link>
		<dc:creator>cammy</dc:creator>
		<pubDate>Fri, 01 May 2009 21:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-59689</guid>
		<description>In your first example how could GenerateID() evaluate to 0 if s_nID is set to 0 but then incremented before the end of the function? Should it not print the following

&lt;pre&gt;1
2
3&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>In your first example how could GenerateID() evaluate to 0 if s_nID is set to 0 but then incremented before the end of the function? Should it not print the following</p>
<pre>1
2
3</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dayu</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-51541</link>
		<dc:creator>Dayu</dc:creator>
		<pubDate>Wed, 18 Mar 2009 20:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-51541</guid>
		<description>I tried the third code without the line &lt;pre&gt; int Something::s_nValue=1;&lt;/pre&gt;. i.e.
&lt;pre&gt;
#include &lt;iostream&gt;
class Something
{
public:
    static int s_nValue;
};

//int Something::s_nValue;

int main()
{
    Something cFirst;

    Something cSecond;
    std::cout &lt;&lt; cSecond.s_nValue;

    return 0;
}
&lt;!--formatted--&gt;&lt;/pre&gt;



I got a compilation error:

.../main.cpp&#124;15&#124;undefined reference to `Something::s_nValue&#039;&#124;.

I also tried &lt;pre&gt; int Something::s_nValue;&lt;/pre&gt; Note that there is no &quot;=1&quot; this time, and everything works out fine with s_nValue=0;
Does this mean &lt;pre&gt; int Something::s_nValue;&lt;/pre&gt; is always needed when we declare a static variable of a class? By the way, I am using Code::Blocks with GCC as the compiler on my Ubuntu.</description>
		<content:encoded><![CDATA[<p>I tried the third code without the line
<pre> int Something::s_nValue=1;</pre>
<p>. i.e.</p>
<pre>
#include &lt;iostream&gt;
class Something
{
public:
    static int s_nValue;
};

//int Something::s_nValue;

int main()
{
    Something cFirst;

    Something cSecond;
    std::cout &lt;&lt; cSecond.s_nValue;

    return 0;
}
<!--formatted--></pre>
<p>I got a compilation error:</p>
<p>&#8230;/main.cpp|15|undefined reference to `Something::s_nValue&#8217;|.</p>
<p>I also tried
<pre> int Something::s_nValue;</pre>
<p> Note that there is no &#8220;=1&#8243; this time, and everything works out fine with s_nValue=0;<br />
Does this mean
<pre> int Something::s_nValue;</pre>
<p> is always needed when we declare a static variable of a class? By the way, I am using Code::Blocks with GCC as the compiler on my Ubuntu.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: luke</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-28673</link>
		<dc:creator>luke</dc:creator>
		<pubDate>Mon, 29 Sep 2008 17:49:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-28673</guid>
		<description>Sorry David. I don&#039;t think I got enough sleep that night. Hope there&#039;s no hard feelings.</description>
		<content:encoded><![CDATA[<p>Sorry David. I don&#8217;t think I got enough sleep that night. Hope there&#8217;s no hard feelings.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
