<?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.12 &#8212; Static member functions</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/812-static-member-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/</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: ankit shukla</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-95963</link>
		<dc:creator>ankit shukla</dc:creator>
		<pubDate>Mon, 05 Sep 2011 05:36:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-95963</guid>
		<description>friend function in c++ is that in which the two classes directly communicate each other.but it breaks the priciple of data hiding, is it</description>
		<content:encoded><![CDATA[<p>friend function in c++ is that in which the two classes directly communicate each other.but it breaks the priciple of data hiding, is it</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: catraeus</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-95302</link>
		<dc:creator>catraeus</dc:creator>
		<pubDate>Sun, 03 Apr 2011 01:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-95302</guid>
		<description>The whole of this example, with all of the static variables and methods, produces dangerous code.  Threading becomes difficult (you have to build your own locks) and anybody can get to the variables from anywhere without the richness of the various c++ tools like boost, etc.  This is completely done without problems, allowing the richness of the various other libraries that are aimed at OS management with a Singleton Pattern.  I like the example (a href=&quot;http://www.yolinux.com/TUTORIALS/C++Singleton.html&quot; title=&quot;here.&quot;&gt;</description>
		<content:encoded><![CDATA[<p>The whole of this example, with all of the static variables and methods, produces dangerous code.  Threading becomes difficult (you have to build your own locks) and anybody can get to the variables from anywhere without the richness of the various c++ tools like boost, etc.  This is completely done without problems, allowing the richness of the various other libraries that are aimed at OS management with a Singleton Pattern.  I like the example (a href=&#8221;http://www.yolinux.com/TUTORIALS/C++Singleton.html&#8221; title=&#8221;here.&#8221;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: codingfreak</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-93340</link>
		<dc:creator>codingfreak</dc:creator>
		<pubDate>Tue, 05 Oct 2010 09:10:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-93340</guid>
		<description>Seems STATIC classes are not supported under C++ ... ??

When I tried to compile the above code I get error saying
&quot;error: a storage class can only be specified for objects and functions&quot;</description>
		<content:encoded><![CDATA[<p>Seems STATIC classes are not supported under C++ &#8230; ??</p>
<p>When I tried to compile the above code I get error saying<br />
&#8220;error: a storage class can only be specified for objects and functions&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SUN</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-87978</link>
		<dc:creator>SUN</dc:creator>
		<pubDate>Tue, 06 Jul 2010 16:58:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-87978</guid>
		<description>Hi leon,

Thanks a lot for the information

Regards!</description>
		<content:encoded><![CDATA[<p>Hi leon,</p>
<p>Thanks a lot for the information</p>
<p>Regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: leon.li</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-87518</link>
		<dc:creator>leon.li</dc:creator>
		<pubDate>Thu, 01 Jul 2010 05:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-87518</guid>
		<description>hi, SUN, I think static constructor is used for :
1.initiating some static member variables of a class;
2.if you don&#039;t write the static constructor, and your class has some static member variables which already given the initial values, the compiler will automated generate a static constructor for you.
3. I think in database singleton design mode, it is useful. Because we don&#039;t want to generate too much accessing thread for the database, it is waste the resource.

thanks.</description>
		<content:encoded><![CDATA[<p>hi, SUN, I think static constructor is used for :<br />
1.initiating some static member variables of a class;<br />
2.if you don&#8217;t write the static constructor, and your class has some static member variables which already given the initial values, the compiler will automated generate a static constructor for you.<br />
3. I think in database singleton design mode, it is useful. Because we don&#8217;t want to generate too much accessing thread for the database, it is waste the resource.</p>
<p>thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SUN</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-86457</link>
		<dc:creator>SUN</dc:creator>
		<pubDate>Mon, 14 Jun 2010 13:16:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-86457</guid>
		<description>Hello Alex,

Can you please explain me what is the use of making a constructor static and when we need to do that ?</description>
		<content:encoded><![CDATA[<p>Hello Alex,</p>
<p>Can you please explain me what is the use of making a constructor static and when we need to do that ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: uma</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-85439</link>
		<dc:creator>uma</dc:creator>
		<pubDate>Thu, 27 May 2010 06:26:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-85439</guid>
		<description>//cStaticClass::getValue(); //Throws an exception, cannot access static methods and variables of an instantiated object of a static class

this error i am not getting 
cStaticClass.getvalue();----&gt; i have written iike this i am not getting any error 
cStaticClass is a object right so we can access member function or data of the claa by dot operator right.

y can u explain me in detail why i am not getting error</description>
		<content:encoded><![CDATA[<p>//cStaticClass::getValue(); //Throws an exception, cannot access static methods and variables of an instantiated object of a static class</p>
<p>this error i am not getting<br />
cStaticClass.getvalue();&#8212;-&gt; i have written iike this i am not getting any error<br />
cStaticClass is a object right so we can access member function or data of the claa by dot operator right.</p>
<p>y can u explain me in detail why i am not getting error</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-84544</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Thu, 13 May 2010 07:37:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-84544</guid>
		<description>Thanks 4lgor1thm...:)</description>
		<content:encoded><![CDATA[<p>Thanks 4lgor1thm&#8230;:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 4lgor1thm</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-84496</link>
		<dc:creator>4lgor1thm</dc:creator>
		<pubDate>Wed, 12 May 2010 13:29:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-84496</guid>
		<description>Hi, Peter

“Second, because all static members are instantiated only once, there is no way to have multiple copies of a pure static class (without cloning the class and renaming it).&quot;

Static Classes can only have one instance derived from them (not an object, but a call to the static class itself.). Non-static classes can have an infinite number of instance derived from them (objects). Consider the example below; it&#039;s an excerpt from a small Console app I wrote in Visual C++ Studio Express 2010:

----------------------------------------------------------------------------------------------
// StaticClasses.cpp : main project file.

#include &quot;stdafx.h&quot;

using namespace System;

//Our pure static class can only contain static items ...
static class StaticClass
{
private:
	static int s_nValue;

public:
	static int getValue(){return s_nValue++;}
};

class DynamicClass
{
private:
	int m_nValue;

public:
	DynamicClass(){m_nValue = 1;}
	int getValue(){return m_nValue++;}
};

int StaticClass::s_nValue = 0;

int main(array ^args)
{
	StaticClass cStaticClass;

	//cStaticClass::getValue(); //Throws an exception, cannot access static methods and variables of an instantiated object of a static class

	//in the tutorial the author said it can be instantiated once
	//This is the reason why it holds on to its value even out of class scope.
	//Here we have one copy, the static class
	Console::WriteLine(L&quot;StaticClass getValue call: &quot; + StaticClass::getValue());
	Console::WriteLine(L&quot;StaticClass getValue call: &quot; + StaticClass::getValue());

	//in order to have multiple copies of the class, we need to create a non-static class, and instantiate at least 2 objects
	DynamicClass cClass1;
	DynamicClass cClass2;

	//here 2 objects are being instantiated from a non-static class; here we have 2 copies, the same way we could use 2 different IDGenerators.
	Console::WriteLine(L&quot;Instantiated Object 1: &quot; + cClass1.getValue());
	Console::WriteLine(L&quot;Instantiated Object 2: &quot; + cClass2.getValue());

    Console::WriteLine(L&quot;Press any key to continue ...&quot;);
	Console::ReadLine();
    return 0;
}

----------------------------------------------------------------------------------------------

&quot;... if you needed two independent IDGenerators, this would not be possible.&quot;

You can only derive one instance from a static class, and it is not an object.

I Hope this helps ...

4lgor1thm</description>
		<content:encoded><![CDATA[<p>Hi, Peter</p>
<p>“Second, because all static members are instantiated only once, there is no way to have multiple copies of a pure static class (without cloning the class and renaming it).&#8221;</p>
<p>Static Classes can only have one instance derived from them (not an object, but a call to the static class itself.). Non-static classes can have an infinite number of instance derived from them (objects). Consider the example below; it&#8217;s an excerpt from a small Console app I wrote in Visual C++ Studio Express 2010:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
// StaticClasses.cpp : main project file.</p>
<p>#include &#8220;stdafx.h&#8221;</p>
<p>using namespace System;</p>
<p>//Our pure static class can only contain static items &#8230;<br />
static class StaticClass<br />
{<br />
private:<br />
	static int s_nValue;</p>
<p>public:<br />
	static int getValue(){return s_nValue++;}<br />
};</p>
<p>class DynamicClass<br />
{<br />
private:<br />
	int m_nValue;</p>
<p>public:<br />
	DynamicClass(){m_nValue = 1;}<br />
	int getValue(){return m_nValue++;}<br />
};</p>
<p>int StaticClass::s_nValue = 0;</p>
<p>int main(array ^args)<br />
{<br />
	StaticClass cStaticClass;</p>
<p>	//cStaticClass::getValue(); //Throws an exception, cannot access static methods and variables of an instantiated object of a static class</p>
<p>	//in the tutorial the author said it can be instantiated once<br />
	//This is the reason why it holds on to its value even out of class scope.<br />
	//Here we have one copy, the static class<br />
	Console::WriteLine(L&#8221;StaticClass getValue call: &#8221; + StaticClass::getValue());<br />
	Console::WriteLine(L&#8221;StaticClass getValue call: &#8221; + StaticClass::getValue());</p>
<p>	//in order to have multiple copies of the class, we need to create a non-static class, and instantiate at least 2 objects<br />
	DynamicClass cClass1;<br />
	DynamicClass cClass2;</p>
<p>	//here 2 objects are being instantiated from a non-static class; here we have 2 copies, the same way we could use 2 different IDGenerators.<br />
	Console::WriteLine(L&#8221;Instantiated Object 1: &#8221; + cClass1.getValue());<br />
	Console::WriteLine(L&#8221;Instantiated Object 2: &#8221; + cClass2.getValue());</p>
<p>    Console::WriteLine(L&#8221;Press any key to continue &#8230;&#8221;);<br />
	Console::ReadLine();<br />
    return 0;<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8220;&#8230; if you needed two independent IDGenerators, this would not be possible.&#8221;</p>
<p>You can only derive one instance from a static class, and it is not an object.</p>
<p>I Hope this helps &#8230;</p>
<p>4lgor1thm</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.learncpp.com/cpp-tutorial/812-static-member-functions/comment-page-1/#comment-84484</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Wed, 12 May 2010 10:15:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/812-static-member-functions/#comment-84484</guid>
		<description>Hi Alex,

Did not understand the following....Can u explain?

&quot;Second, because all static members are instantiated only once, there is no way to have multiple copies of a pure static class (without cloning the class and renaming it). For example, if you needed two independent IDGenerators, this would not be possible.&quot;

What do u mean by two IDgenerators? Is it two classes?
Can some one explain the above paragraph in detail</description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>Did not understand the following&#8230;.Can u explain?</p>
<p>&#8220;Second, because all static members are instantiated only once, there is no way to have multiple copies of a pure static class (without cloning the class and renaming it). For example, if you needed two independent IDGenerators, this would not be possible.&#8221;</p>
<p>What do u mean by two IDgenerators? Is it two classes?<br />
Can some one explain the above paragraph in detail</p>
]]></content:encoded>
	</item>
</channel>
</rss>

