<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Friends &#187; static_cast</title>
	<atom:link href="http://www.codingfriends.com/index.php/tag/static_cast/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:11:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Static_cast &#8211; cpp</title>
		<link>http://www.codingfriends.com/index.php/2010/02/08/static_cast-cpp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=static_cast-cpp</link>
		<comments>http://www.codingfriends.com/index.php/2010/02/08/static_cast-cpp/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:31:51 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[static_cast]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=651</guid>
		<description><![CDATA[Static casting (static_cast) is when you want to change the type of the variable e.g. if you want to have a the number of pies that are left to be 0.5 instead of a whole value then you would need to change the integer value to a double. The static_cast can change one type to [...]]]></description>
			<content:encoded><![CDATA[<p>Static casting (static_cast) is when you want to change the type of the variable e.g. if you want to have a the number of pies that are left to be 0.5 instead of a whole value then you would need to change the integer value to a double.  The static_cast can change one type to another, as long as it is compatible.</p>
<p>The general syntax for static_cast is</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">returnvalue <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span>returntype<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>value to cast<span style="color: #008000;">&#41;</span></pre></div></div>

<p>Where the return value is the value returned from the casting, returntype is the variable type that you want to have (e.g. double) and the value to cast speaks for itself.</p>
<p>For the example above about pies, the code would be</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">     <span style="color: #0000ff;">int</span> pie <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
     <span style="color: #0000ff;">double</span> fl <span style="color: #000080;">=</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>pie<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The static_cast(ing) and also other types of casting are the long form as such compared to the standard C version of</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">   <span style="color: #0000ff;">double</span> fl <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span><span style="color: #008000;">&#41;</span>pie<span style="color: #008080;">;</span></pre></div></div>

<p>But with the static_cast you can be sure that the implementation will be type checked and also because of the classes etc then you need to type check the results unless you may have some value that is not want you was wanting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/02/08/static_cast-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

