<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Banco do Conhecimento &#187; C++</title>
	<atom:link href="http://arqdecompufs.wordpress.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://arqdecompufs.wordpress.com</link>
	<description>Thiago de Mendonça Modesto e Vitor Almeida Costa</description>
	<lastBuildDate>Wed, 13 Aug 2008 03:40:42 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='arqdecompufs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/a118e92df3d2f10f28d77474db60021b?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Banco do Conhecimento &#187; C++</title>
		<link>http://arqdecompufs.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://arqdecompufs.wordpress.com/osd.xml" title="Banco do Conhecimento" />
		<item>
		<title>Burlando a orientação a objetos do C++ com ponteiros</title>
		<link>http://arqdecompufs.wordpress.com/2008/07/22/burlando-a-orientacao-a-objetos-do-c-com-ponteiros/</link>
		<comments>http://arqdecompufs.wordpress.com/2008/07/22/burlando-a-orientacao-a-objetos-do-c-com-ponteiros/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 17:56:49 +0000</pubDate>
		<dc:creator>Thiago e Vitor</dc:creator>
				<category><![CDATA[Depois da primeira prova]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://arqdecompufs.wordpress.com/?p=13</guid>
		<description><![CDATA[C++ introduziu alguns conceitos de Orientação a Objetos à linguagem C. Dessa forma podemos trabalhar com encapsulamentos e todas as demais vantagens de uma linguagem Orientada a Objetos. Porém, C++ manteve uma característica importante de C: os ponteiros.
 Devido à existência de ponteiros em C++ torna-se possível burlar a Orientação a Objetos suportada na linguagem. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arqdecompufs.wordpress.com&blog=3856172&post=13&subd=arqdecompufs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>C++ introduziu alguns conceitos de Orientação a Objetos à linguagem C. Dessa forma podemos trabalhar com encapsulamentos e todas as demais vantagens de uma linguagem Orientada a Objetos. Porém, C++ manteve uma característica importante de C: os ponteiros.</p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;"><span> </span>Devido à existência de ponteiros em C++ torna-se possível burlar a Orientação a Objetos suportada na linguagem. Afinal os ponteiros fazem referência direta ao endereço e não à variável.</p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;"><span> </span>Segue abaixo um exemplo de código de como isso pode ser feito:</p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&quot;">class</span></strong><span style="font-size:10pt;font-family:&quot;"> </span><span style="font-size:10pt;font-family:&quot;">Burlando</span><span style="font-size:10pt;font-family:&quot;"> {</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&quot;">private</span></strong><span style="font-size:10pt;font-family:&quot;">: </span><strong><span style="font-size:10pt;font-family:&quot;">float</span></strong><span style="font-size:10pt;font-family:&quot;"> </span><span style="font-size:10pt;font-family:&quot;">array</span><span style="font-size:10pt;font-family:&quot;"> [] = {2,3,4,5,6,7};</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10pt;font-family:&quot;">public</span></strong><span style="font-size:10pt;font-family:&quot;">:</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span><strong>Burlando</strong>();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">virtual</span></strong><span style="font-size:10pt;font-family:&quot;"> <strong>~Burlando</strong>();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">float</span></strong><span style="font-size:10pt;font-family:&quot;">* </span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;">;</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><span style="font-size:10pt;font-family:&quot;">//retorna o endereco da primeira posicao do array</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">int</span></strong><span style="font-size:10pt;font-family:&quot;"> <strong>getAdress</strong>(){</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">return</span></strong><span style="font-size:10pt;font-family:&quot;"> &amp;</span><span style="font-size:10pt;font-family:&quot;">array</span><span style="font-size:10pt;font-family:&quot;">[0];</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><span style="font-size:10pt;font-family:&quot;">//imprime o array</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">void</span></strong><span style="font-size:10pt;font-family:&quot;"> <strong>imprimeArray</strong>(){</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">for</span></strong><span style="font-size:10pt;font-family:&quot;"> (</span><strong><span style="font-size:10pt;font-family:&quot;">int</span></strong><span style="font-size:10pt;font-family:&quot;"> i = 0; i==6; i++){</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>cout&lt;&lt;</span><span style="font-size:10pt;font-family:&quot;">array</span><span style="font-size:10pt;font-family:&quot;">[i];</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">void</span></strong><span style="font-size:10pt;font-family:&quot;"> <strong>main</strong>(){</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><span style="font-size:10pt;font-family:&quot;">Burlando</span><span style="font-size:10pt;font-family:&quot;"> obj = </span><strong><span style="font-size:10pt;font-family:&quot;">new</span></strong><span style="font-size:10pt;font-family:&quot;"> Burlando();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><span style="font-size:10pt;font-family:&quot;">obj.imprimeArray();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>*</span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;"> = getAdress();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><strong><span style="font-size:10pt;font-family:&quot;">for</span></strong><span style="font-size:10pt;font-family:&quot;"> (</span><strong><span style="font-size:10pt;font-family:&quot;">int</span></strong><span style="font-size:10pt;font-family:&quot;"> c = 0; c == 6; c++){</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span><span> </span>//faz o quadrado do valor do array</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span></span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;"> = </span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;"> * </span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;">;</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span><span> </span></span><span style="font-size:10pt;font-family:&quot;">//ponteiro aponta p/ proxima posicao do array</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>*</span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;"> = </span><span style="font-size:10pt;font-family:&quot;">ponteiro</span><span style="font-size:10pt;font-family:&quot;"> + 2;<span> </span></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>obj.imprimeArray();</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;"><span style="font-size:10pt;font-family:&quot;">};</span></p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;">
<p class="MsoBodyTextIndent2" style="margin-top:6pt;">Neste exemplo, nós criamos um array do tipo <em>float</em> como privado. Criamos como público um ponteiro que aponta para float e um método do tipo int getAdress que retorna o endereço da primeira posição do array privado.</p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;"><span> </span>No método main nós instanciamos um objeto da classe, mandamos imprimir os valores do array apenas para comprovar a quebra da Orientação a Objeto. Em seguida atribuímos ao ponteiro o resultado do método getAdress e em seguida modificamos um a um os valores do array, calculando o quadrado deles.</p>
<p class="MsoBodyTextIndent2" style="margin-top:6pt;"><span> </span>Logo depois, nós mandamos imprimir os valores do array novamente para termos certeza que eles foram modificados. Dessa forma pudemos constatar que a Orientação a Objeto foi burlada.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/arqdecompufs.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/arqdecompufs.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arqdecompufs.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arqdecompufs.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arqdecompufs.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arqdecompufs.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arqdecompufs.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arqdecompufs.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arqdecompufs.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arqdecompufs.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arqdecompufs.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arqdecompufs.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arqdecompufs.wordpress.com&blog=3856172&post=13&subd=arqdecompufs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://arqdecompufs.wordpress.com/2008/07/22/burlando-a-orientacao-a-objetos-do-c-com-ponteiros/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e6b41501e336727e7bbf13e21c65f283?s=96&#38;d=identicon" medium="image">
			<media:title type="html">Thiago e Vitor</media:title>
		</media:content>
	</item>
	</channel>
</rss>