<?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, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: dog44wgm</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-96390</link>
		<dc:creator>dog44wgm</dc:creator>
		<pubDate>Tue, 15 Nov 2011 22:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-96390</guid>
		<description>Definitely 0 according to the Standard (draft 2011): 
http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2011/n3242.pdf

&quot;Variables with static storage duration (3.7.1) or thread storage duration (3.7.2) shall be zero-initialized (8.5)
before any other initialization takes place&quot;.</description>
		<content:encoded><![CDATA[<p>Definitely 0 according to the Standard (draft 2011):<br />
<a href="http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2011/n3242.pdf" rel="nofollow">http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2011/n3242.pdf</a></p>
<p>&#8220;Variables with static storage duration (3.7.1) or thread storage duration (3.7.2) shall be zero-initialized (8.5)<br />
before any other initialization takes place&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Static variables in classes &#124; Reading List</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-95950</link>
		<dc:creator>Static variables in classes &#124; Reading List</dc:creator>
		<pubDate>Thu, 01 Sep 2011 05:16:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-95950</guid>
		<description>[...] Static variable member class Share this:TwitterFacebookLike this:LikeBe the first to like this post.   This entry was posted in Uncategorized. Bookmark the permalink.    &#8592; May I have your&#160;address? [...]</description>
		<content:encoded><![CDATA[<p>[...] Static variable member class Share this:TwitterFacebookLike this:LikeBe the first to like this post.   This entry was posted in Uncategorized. Bookmark the permalink.    &larr; May I have your&nbsp;address? [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashish79</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-95525</link>
		<dc:creator>Ashish79</dc:creator>
		<pubDate>Mon, 06 Jun 2011 12:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-95525</guid>
		<description>Hi,
Can we call non-static functions with static objects?</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Can we call non-static functions with static objects?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abbas</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-95021</link>
		<dc:creator>abbas</dc:creator>
		<pubDate>Fri, 10 Dec 2010 12:57:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-95021</guid>
		<description>hey alex i have to questions 
Q1:what means about &quot;hidden argument to the function&quot; using this pointer.
Q2: what means &quot;function is called for an object&quot;.</description>
		<content:encoded><![CDATA[<p>hey alex i have to questions<br />
Q1:what means about &#8220;hidden argument to the function&#8221; using this pointer.<br />
Q2: what means &#8220;function is called for an object&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: je789456123</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-94896</link>
		<dc:creator>je789456123</dc:creator>
		<pubDate>Tue, 09 Nov 2010 16:54:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-94896</guid>
		<description>&lt;a href=&quot;&quot; title=&quot;&quot; rel=&quot;nofollow&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;cite&gt; &lt;code&gt; &lt;del datetime=&quot;&quot;&gt; &lt;em&gt; &lt;i&gt; &lt;q cite=&quot;&quot;&gt; &lt;strike&gt; &lt;strong&gt; &lt;pre&gt; 
It is mentioned at the end of section 8.11 that &quot;By making the lookup table static, only one copy exists for all objects, rather than a copy for each object instantiated. This can save substantial amounts of memory&quot;.  This is exactly what I want to do using an array.  However, I don&#039;t know how to initialize the static array.  I know that for small arrays I could do something like:

int SomeClass::myArray[4] = {1, 5, 9, 10};

but is there any way to initialize the array by using a loop?

Thanks in advance!</description>
		<content:encoded><![CDATA[<p><a href="" title="" rel="nofollow"> <abbr title=""> <acronym title=""> <b><br />
<blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
<pre>
It is mentioned at the end of section 8.11 that "By making the lookup table static, only one copy exists for all objects, rather than a copy for each object instantiated. This can save substantial amounts of memory".  This is exactly what I want to do using an array.  However, I don't know how to initialize the static array.  I know that for small arrays I could do something like:

int SomeClass::myArray[4] = {1, 5, 9, 10};

but is there any way to initialize the array by using a loop?

Thanks in advance!</pre>
<p></strong></strike></q></i></em></del></code></cite></p></blockquote>
<p></b></acronym></abbr></a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D.M. Ryan</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-91646</link>
		<dc:creator>D.M. Ryan</dc:creator>
		<pubDate>Wed, 08 Sep 2010 10:51:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-91646</guid>
		<description>Did you try changing &lt;pre&gt;static ShipType::Format m_format;&lt;/pre&gt; to &lt;pre&gt;static Format m_format;&lt;/pre&gt; ? 

In the examples above, the class scope isn&#039;t added when a static variable is declared within the class itself. 

That fix may not work, but it&#039;s worth a try. &lt;pre&gt;ShipType::Format m_format = ShipType::verbose;&lt;/pre&gt; is correct.</description>
		<content:encoded><![CDATA[<p>Did you try changing
<pre>static ShipType::Format m_format;</pre>
<p> to
<pre>static Format m_format;</pre>
<p> ? </p>
<p>In the examples above, the class scope isn&#8217;t added when a static variable is declared within the class itself. </p>
<p>That fix may not work, but it&#8217;s worth a try.
<pre>ShipType::Format m_format = ShipType::verbose;</pre>
<p> is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Poke</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-91018</link>
		<dc:creator>Poke</dc:creator>
		<pubDate>Sat, 28 Aug 2010 05:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-91018</guid>
		<description>Hello!  I&#039;m having an issue with a static member variable...my g++ compiler is giving me the error:  undefined reference to `ShipType::m_format&#039;.  Nearly all of the comments I&#039;ve read say to instantiate the static outside the class, which I have done.  Here&#039;s my code snippet:

&lt;pre&gt;
//ShipType.h
class ShipType
{
public:
	enum Type {null, DD, SS, CA, BB, CV};
	enum Format {abbreviated, verbose};
...
	static string toString(ShipType::Type);
...
protected:
	static ShipType::Format m_format;
};

//ShipType.cpp
#include &quot;ShipType.h&quot;
...
ShipType::Format m_format = ShipType::verbose; //Here&#039;s where I&#039;ve instantiated the static

string ShipType::toString(ShipType::Type t)
{
...
  if (ShipType::abbreviated == ShipType::m_format) //error message applies to this LOC
    retVal = shipStringsA[t];
  else
    retVal = shipStringsV[t];
  return retVal;
)//toString
&lt;/pre&gt;

Thank you in advance...

Poke</description>
		<content:encoded><![CDATA[<p>Hello!  I&#8217;m having an issue with a static member variable&#8230;my g++ compiler is giving me the error:  undefined reference to `ShipType::m_format&#8217;.  Nearly all of the comments I&#8217;ve read say to instantiate the static outside the class, which I have done.  Here&#8217;s my code snippet:</p>
<pre>
//ShipType.h
class ShipType
{
public:
	enum Type {null, DD, SS, CA, BB, CV};
	enum Format {abbreviated, verbose};
...
	static string toString(ShipType::Type);
...
protected:
	static ShipType::Format m_format;
};

//ShipType.cpp
#include &quot;ShipType.h&quot;
...
ShipType::Format m_format = ShipType::verbose; //Here&#39;s where I&#39;ve instantiated the static

string ShipType::toString(ShipType::Type t)
{
...
  if (ShipType::abbreviated == ShipType::m_format) //error message applies to this LOC
    retVal = shipStringsA[t];
  else
    retVal = shipStringsV[t];
  return retVal;
)//toString
</pre>
<p>Thank you in advance&#8230;</p>
<p>Poke</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dawid Chemloul</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-89725</link>
		<dc:creator>Dawid Chemloul</dc:creator>
		<pubDate>Fri, 06 Aug 2010 13:11:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-89725</guid>
		<description>-- edit deleted</description>
		<content:encoded><![CDATA[<p>&#8211; edit deleted</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dawid Chemloul</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-89723</link>
		<dc:creator>Dawid Chemloul</dc:creator>
		<pubDate>Fri, 06 Aug 2010 13:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-89723</guid>
		<description>I have questions and maybe some answers.

1. Is static in function variable guaranteed to be initialized (created) at first function call or is it compiler dependent?

as for singletons - it is possible to use static member to create singleton with nice encapsulation but I would rather use static variable in function if answer for my first question is yes.

Since if you will try make some static singleton objects - or some static objects using your singletons then initialisation order of all those global static globals need to be maintained with care.

Since it is possible that you will create a singleton instance before global member was initialised - then initialisation of global member will override previous usage... this seamnot to pose problems used this way in VS2010

Example:
&lt;pre&gt;
class Singleton
{
public:
  static Singleton &amp; getInstance()
  {
     static Singleton *instance = 0;
     if( ! instance )
     {
        instance = new Singleton();
     }
     return *instance;
  }
};
&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I have questions and maybe some answers.</p>
<p>1. Is static in function variable guaranteed to be initialized (created) at first function call or is it compiler dependent?</p>
<p>as for singletons &#8211; it is possible to use static member to create singleton with nice encapsulation but I would rather use static variable in function if answer for my first question is yes.</p>
<p>Since if you will try make some static singleton objects &#8211; or some static objects using your singletons then initialisation order of all those global static globals need to be maintained with care.</p>
<p>Since it is possible that you will create a singleton instance before global member was initialised &#8211; then initialisation of global member will override previous usage&#8230; this seamnot to pose problems used this way in VS2010</p>
<p>Example:</p>
<pre>
class Singleton
{
public:
  static Singleton &amp; getInstance()
  {
     static Singleton *instance = 0;
     if( ! instance )
     {
        instance = new Singleton();
     }
     return *instance;
  }
};
<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: srikanth</title>
		<link>http://www.learncpp.com/cpp-tutorial/811-static-member-variables/comment-page-1/#comment-88993</link>
		<dc:creator>srikanth</dc:creator>
		<pubDate>Sat, 24 Jul 2010 03:23:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/811-static-member-variables/#comment-88993</guid>
		<description>i have a small question is static variable can be used in defining singleton of a class more efficently</description>
		<content:encoded><![CDATA[<p>i have a small question is static variable can be used in defining singleton of a class more efficently</p>
]]></content:encoded>
	</item>
</channel>
</rss>

