<?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: Explicit and Implicit constructors in C++</title>
	<atom:link href="http://phalanx.spartansoft.org/2009/04/06/explicit-and-implicit-constructors-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://phalanx.spartansoft.org/2009/04/06/explicit-and-implicit-constructors-in-c/</link>
	<description>Whatever happens, SPARTAN&#039;S code must stand ... Or at least crash responsibly.</description>
	<lastBuildDate>Thu, 12 Jan 2012 22:40:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: yrtz</title>
		<link>http://phalanx.spartansoft.org/2009/04/06/explicit-and-implicit-constructors-in-c/comment-page-1/#comment-4288</link>
		<dc:creator>yrtz</dc:creator>
		<pubDate>Mon, 16 Aug 2010 16:50:38 +0000</pubDate>
		<guid isPermaLink="false">http://codespartan.org/blog/?p=297#comment-4288</guid>
		<description>C++ is full of crap.</description>
		<content:encoded><![CDATA[<p>C++ is full of crap.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milot Shala</title>
		<link>http://phalanx.spartansoft.org/2009/04/06/explicit-and-implicit-constructors-in-c/comment-page-1/#comment-57</link>
		<dc:creator>Milot Shala</dc:creator>
		<pubDate>Mon, 06 Jul 2009 08:17:19 +0000</pubDate>
		<guid isPermaLink="false">http://codespartan.org/blog/?p=297#comment-57</guid>
		<description>&lt;a href=&quot;#comment-97&quot; rel=&quot;nofollow&quot;&gt;@Pietro&lt;/a&gt;

With the code you provided in it&#039;s constructor your class accepts an integer with it&#039;s default value set to 1, if no parameters has passed to the constructor, it will have the 1 as value, in your case if you try to do this one:

myClass *mycls = new MyClass();
*mycls = 100;

the a would get the value of 100 so also in this case you should use explicit keyword. But in the other hand, if you have a class that it&#039;s constructor have two parameters (I extended your class below):

class MyClass
{
public:
  MyClass(int a, int b = 1);
  void printVals();
private:
  int _a;
  int _b;
};

and we initiate it&#039;s instance like the code below:

 MyClass *m = new MyClass(2,2);
 *m = 111;

the b variable will take it&#039;s default value and the a variable will have the value of 111, and as you might expect this is not correct because you cannot allow programmers to use your class in this way, and you should use explicit keywords again :)</description>
		<content:encoded><![CDATA[<p><a href="#comment-97" rel="nofollow">@Pietro</a></p>
<p>With the code you provided in it&#8217;s constructor your class accepts an integer with it&#8217;s default value set to 1, if no parameters has passed to the constructor, it will have the 1 as value, in your case if you try to do this one:</p>
<p>myClass *mycls = new MyClass();<br />
*mycls = 100;</p>
<p>the a would get the value of 100 so also in this case you should use explicit keyword. But in the other hand, if you have a class that it&#8217;s constructor have two parameters (I extended your class below):</p>
<p>class MyClass<br />
{<br />
public:<br />
  MyClass(int a, int b = 1);<br />
  void printVals();<br />
private:<br />
  int _a;<br />
  int _b;<br />
};</p>
<p>and we initiate it&#8217;s instance like the code below:</p>
<p> MyClass *m = new MyClass(2,2);<br />
 *m = 111;</p>
<p>the b variable will take it&#8217;s default value and the a variable will have the value of 111, and as you might expect this is not correct because you cannot allow programmers to use your class in this way, and you should use explicit keywords again <img src='http://phalanx.spartansoft.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pietro</title>
		<link>http://phalanx.spartansoft.org/2009/04/06/explicit-and-implicit-constructors-in-c/comment-page-1/#comment-56</link>
		<dc:creator>Pietro</dc:creator>
		<pubDate>Sun, 05 Jul 2009 23:49:17 +0000</pubDate>
		<guid isPermaLink="false">http://codespartan.org/blog/?p=297#comment-56</guid>
		<description>Can you tell me what happens with this code?

class myClass {
public:
   explicit myClass(int a = 1);
};

The constructor should be treated as a one parameter one, right? The default value should have no effect for what &quot;explicit&quot; is concerned...</description>
		<content:encoded><![CDATA[<p>Can you tell me what happens with this code?</p>
<p>class myClass {<br />
public:<br />
   explicit myClass(int a = 1);<br />
};</p>
<p>The constructor should be treated as a one parameter one, right? The default value should have no effect for what &#8220;explicit&#8221; is concerned&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

