<?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: 10.1 &#8212; Constructor initialization lists</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/</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: Nikhil Singhal</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-95645</link>
		<dc:creator>Nikhil Singhal</dc:creator>
		<pubDate>Wed, 29 Jun 2011 12:23:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-95645</guid>
		<description>Hi,

The Ans is Very Simple......

B constructor first called, because first declaration part is done then A&#039;s Constructor is called, so here B&#039;s object is created first.
I think you got the answer
if have any confusion run the following code in debug mode:

class B {
	int BValue;
public:
	B()
	{
		BValue = 0;
		printf(&quot;\n Class B Constructor is Called&quot;);
	}
};
class A {
	int value;
	B bMember;

public:
	A() 
	{
	value = 0;
	printf(&quot;\n Class A Constructor is Called \n &quot;);
	}
};


int main(int argc, char* argv[])
{
	A a1;
	return 0;
}</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>The Ans is Very Simple&#8230;&#8230;</p>
<p>B constructor first called, because first declaration part is done then A&#8217;s Constructor is called, so here B&#8217;s object is created first.<br />
I think you got the answer<br />
if have any confusion run the following code in debug mode:</p>
<p>class B {<br />
	int BValue;<br />
public:<br />
	B()<br />
	{<br />
		BValue = 0;<br />
		printf(&#8220;\n Class B Constructor is Called&#8221;);<br />
	}<br />
};<br />
class A {<br />
	int value;<br />
	B bMember;</p>
<p>public:<br />
	A()<br />
	{<br />
	value = 0;<br />
	printf(&#8220;\n Class A Constructor is Called \n &#8220;);<br />
	}<br />
};</p>
<p>int main(int argc, char* argv[])<br />
{<br />
	A a1;<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vvidhu1988</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-95365</link>
		<dc:creator>vvidhu1988</dc:creator>
		<pubDate>Sun, 24 Apr 2011 10:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-95365</guid>
		<description>hi i have a question. Let say there is class A and Class B

Class A {
 int value,
 B bMember,
 
 Public:
  A() {
   value = 0;
  }
};

here when i create an object to Class A say 

A aMember;

Is the constructor of class A is called and initializes &#039;value&#039; to 0 or before calling Class A&#039;s constructor, whether Calss B&#039;s constructor will be called? since we also have object(bmember) of class type B.

Please explain when class B&#039;s constructor will be called.

Whether in the above code i need to initialize &#039;bMember&#039; of class type B in the Class A&#039;s constructor?? since bMember is also a member in class A. I don&#039;t think it is a proper implementation. Can anyone explain?</description>
		<content:encoded><![CDATA[<p>hi i have a question. Let say there is class A and Class B</p>
<p>Class A {<br />
 int value,<br />
 B bMember,</p>
<p> Public:<br />
  A() {<br />
   value = 0;<br />
  }<br />
};</p>
<p>here when i create an object to Class A say </p>
<p>A aMember;</p>
<p>Is the constructor of class A is called and initializes &#8216;value&#8217; to 0 or before calling Class A&#8217;s constructor, whether Calss B&#8217;s constructor will be called? since we also have object(bmember) of class type B.</p>
<p>Please explain when class B&#8217;s constructor will be called.</p>
<p>Whether in the above code i need to initialize &#8216;bMember&#8217; of class type B in the Class A&#8217;s constructor?? since bMember is also a member in class A. I don&#8217;t think it is a proper implementation. Can anyone explain?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: helbawi</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-95358</link>
		<dc:creator>helbawi</dc:creator>
		<pubDate>Fri, 22 Apr 2011 18:47:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-95358</guid>
		<description>hi,I have question if I used this way , is my program has more safe?</description>
		<content:encoded><![CDATA[<p>hi,I have question if I used this way , is my program has more safe?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cooltoad</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-95164</link>
		<dc:creator>cooltoad</dc:creator>
		<pubDate>Tue, 08 Feb 2011 03:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-95164</guid>
		<description>You can access static data from non-static member functions but not the vice versa.

Imagine that the static data is never tied to an object and hence no this pointer.
It is something like a global variabble for that class. That is why you can access by ClassName::static_variable.

If the member function was static, which means it can be invoked even w/o an object being created which means it cannot access non-static data which are tied to this pointer.</description>
		<content:encoded><![CDATA[<p>You can access static data from non-static member functions but not the vice versa.</p>
<p>Imagine that the static data is never tied to an object and hence no this pointer.<br />
It is something like a global variabble for that class. That is why you can access by ClassName::static_variable.</p>
<p>If the member function was static, which means it can be invoked even w/o an object being created which means it cannot access non-static data which are tied to this pointer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: subhransu</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-93558</link>
		<dc:creator>subhransu</dc:creator>
		<pubDate>Tue, 12 Oct 2010 10:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-93558</guid>
		<description>in case this slipped from your radar
The Constructor initialize list need to initialize always for following 
1) Refrence Variables,
2) Const Variables 
3) base class constructor(having variable number of arguments).</description>
		<content:encoded><![CDATA[<p>in case this slipped from your radar<br />
The Constructor initialize list need to initialize always for following<br />
1) Refrence Variables,<br />
2) Const Variables<br />
3) base class constructor(having variable number of arguments).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-92514</link>
		<dc:creator>Rahul</dc:creator>
		<pubDate>Thu, 23 Sep 2010 07:53:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-92514</guid>
		<description>Even if it appears that m_nValue[] is accessed outside the class &quot;Somethig&quot;, but actually it is not.
In the statement &quot;const int Something::m_nValue[] = {5, 6, 7}&quot;, we are accessing the array from inside the class. It is evident from the &quot;Something::&quot;.</description>
		<content:encoded><![CDATA[<p>Even if it appears that m_nValue[] is accessed outside the class &#8220;Somethig&#8221;, but actually it is not.<br />
In the statement &#8220;const int Something::m_nValue[] = {5, 6, 7}&#8221;, we are accessing the array from inside the class. It is evident from the &#8220;Something::&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-85905</link>
		<dc:creator>Martin</dc:creator>
		<pubDate>Fri, 04 Jun 2010 07:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-85905</guid>
		<description>Comment by Ashish
&quot;...static member data are only accessible to static member function.&quot;

However i am able to access the static member m_nValue from non-static member function GetValue(), as shown in the example below:
//File static.h
class Something
{
private:
	static const int m_nValue[3];

public:
	Something()
	{
	}

	int GetValue(int nIndex)
	{
		return m_nValue[nIndex];
	}

};

//File static.cpp
int _tmain(int argc, _TCHAR* argv[]) //using visual studio 2005
{
	Something a;
	printf (&quot;%d\n%d\n%d\n&quot;, a.GetValue(0), a.GetValue(1), a.GetValue(2));

	return 0;
}</description>
		<content:encoded><![CDATA[<p>Comment by Ashish<br />
&#8220;&#8230;static member data are only accessible to static member function.&#8221;</p>
<p>However i am able to access the static member m_nValue from non-static member function GetValue(), as shown in the example below:<br />
//File static.h<br />
class Something<br />
{<br />
private:<br />
	static const int m_nValue[3];</p>
<p>public:<br />
	Something()<br />
	{<br />
	}</p>
<p>	int GetValue(int nIndex)<br />
	{<br />
		return m_nValue[nIndex];<br />
	}</p>
<p>};</p>
<p>//File static.cpp<br />
int _tmain(int argc, _TCHAR* argv[]) //using visual studio 2005<br />
{<br />
	Something a;<br />
	printf (&#8220;%d\n%d\n%d\n&#8221;, a.GetValue(0), a.GetValue(1), a.GetValue(2));</p>
<p>	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashish</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-73868</link>
		<dc:creator>Ashish</dc:creator>
		<pubDate>Tue, 08 Dec 2009 15:41:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-73868</guid>
		<description>class Something
{
private:
    static const int m_nValue[3];
public:
    Something()
    {
    }
};

const int Something::m_nValue[] = {5, 6, 7}




&#039;m_nValue&#039; is a private data member of the class. So how can you access it outside the class and initialize? Ans also static member data are only accessible to static member function.

Thanks in advance</description>
		<content:encoded><![CDATA[<p>class Something<br />
{<br />
private:<br />
    static const int m_nValue[3];<br />
public:<br />
    Something()<br />
    {<br />
    }<br />
};</p>
<p>const int Something::m_nValue[] = {5, 6, 7}</p>
<p>&#8216;m_nValue&#8217; is a private data member of the class. So how can you access it outside the class and initialize? Ans also static member data are only accessible to static member function.</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: srividya</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-70432</link>
		<dc:creator>srividya</dc:creator>
		<pubDate>Fri, 16 Oct 2009 08:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-70432</guid>
		<description>Its a just an awesome example</description>
		<content:encoded><![CDATA[<p>Its a just an awesome example</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: const variable in C++ class - CodeCall Programming Forum</title>
		<link>http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/comment-page-1/#comment-65428</link>
		<dc:creator>const variable in C++ class - CodeCall Programming Forum</dc:creator>
		<pubDate>Sat, 01 Aug 2009 19:08:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/101-constructor-initialization-lists/#comment-65428</guid>
		<description>[...] to be const. You can initialize const member variables in a class in the constructor, using an initialization list. Using these lists is how you should set any necessary member variables for functions, since [...]</description>
		<content:encoded><![CDATA[<p>[...] to be const. You can initialize const member variables in a class in the constructor, using an initialization list. Using these lists is how you should set any necessary member variables for functions, since [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

