<?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>C++ Source &#187; C++</title>
	<atom:link href="http://cppsource.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://cppsource.com</link>
	<description>Your Source for C++ Information</description>
	<lastBuildDate>Wed, 05 Jan 2011 17:12:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>When Should You Create A Virtual Function?</title>
		<link>http://cppsource.com/2009/06/when-should-you-create-a-virtual-function/</link>
		<comments>http://cppsource.com/2009/06/when-should-you-create-a-virtual-function/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:58:19 +0000</pubDate>
		<dc:creator>carlos</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://cppsource.com/?p=55</guid>
		<description><![CDATA[One of the questions raised by people starting to use C++ and virtual functions is: when should I use virtual functions? To answer this question, you need to understand the reason why virtual functions exist in the first place. A virtual function is a mechanism used for polymorphism in the C++ language. The standard is [...]]]></description>
			<content:encoded><![CDATA[<p>One of the questions raised by people starting to use C++ and virtual functions is: when should I use virtual functions?</p>
<p>To answer this question, you need to understand the reason why virtual functions exist in the first place.</p>
<p>A virtual function is a mechanism used for polymorphism in the C++ language. The standard is example is the drawing method of a shape class.
<pre class="code">
class Shape { public virtual void draw(); }
class Rectangle : public Shape {
  public virtual void draw();
}
</pre>
<p>What is happening here is that the&nbsp;<strong>draw</strong> method&nbsp;varies between Shape and Rectangle. Therefore, it doesn&#8217;t make sense to have only one implementation. You need to have one version of draw for each of the classes Shape and Rectangle.</p>
<p>Whenever you have a situation where classes in the same hierarchy need different implementations, then <strong>virtual</strong> is the keyword you need to use. With virtual we are free to redefine a member function on a derived class.</p>
<p>On the other hand, member functions that were not defined with the virtual keyword cannot be redefined by derived classes. The reason for that is that, since &#8220;virtual&#8221; is not used,&nbsp;the compiler doesn&#8217;t know about different versions of the member function on the derived classes. Therefore, the compiler will call the <strong>wrong version </strong>of&nbsp;the member function.<br />
<h2>General Techniques</h2>
<p>Programmers diverge on the general technique used to say if a method will be virtual or not. Some people believe that you should make all, or at least most of your methods virtual. The idea is that you never know what might be useful to override later, so it is better to leave the options open.</p>
<p>The other group of developers believe that it is better to define only a few member functions as virtual. The reason is that then you will have more control on what the derived classes can do.</p>
<p>The arguments on both sides are good, and as most things in programming, it comes to choosing a side and sticking to it.<br />
<h2>Conclusion</h2>
<p>Virtual functions are the main mechanism that allows different behavior for classes in the same hierarchy. In this way, we should be careful in defining what virtual functions are virtual and what are not. Understanding the virtual keyword you have better ways to defining correct behavior in your classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://cppsource.com/2009/06/when-should-you-create-a-virtual-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some features of the C++0x standard</title>
		<link>http://cppsource.com/2009/04/some-features-of-the-c0x-standard/</link>
		<comments>http://cppsource.com/2009/04/some-features-of-the-c0x-standard/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 04:25:26 +0000</pubDate>
		<dc:creator>carlos</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[standard]]></category>

		<guid isPermaLink="false">http://cppsource.com/?p=17</guid>
		<description><![CDATA[C++ is growing and changing. As has been the case for the last 20 years, C++ has been developing new features as a response to the changes in computing. The latest trend of changes in the C++ language is due to the update of the Standard. A work that has taken many years, the new [...]]]></description>
			<content:encoded><![CDATA[<p>C++ is growing and changing. As has been the case for the last 20 years, C++ has been developing new features as a response to the changes in computing.<br />
The latest trend of changes in the C++ language is due to the update of the Standard.</p>
<p>A work that has taken many years, the new standard that is by now only known as C++0x (where x will be probably 9) will add many features that will change the way we develop software in C++.</p>
<h2>Improved Templates</h2>
<p>Templates are the feature in C++ that was used to create reusable containers for any object. Thanks to templates we have now a powerful standard library, with  containers (such as vectors, lists, trees, and strings), and algorithms that operate on these containers.</p>
<p>On the new standard, templates will be improved by providing information on the types that can be used to specialize a template. This is a form of type inference that will make templates much more useful (and with better error codes).</p>
<p>Another nice feature is the addition of auto detection of variable types. Since the type system of C++ is very sophisticated, it makes sense to have a feature in the language to allow types to be automatically detected. The language will use the keyword <strong>auto</strong> to determine that a variable has the same type as the right hand side on an assignment. So, something as</p>
<p>auto a = new MyObject(); </p>
<p>is sufficient to create a variable of the type MyObject. Notice that we just need to write MyObject once (while nowadays we needed to repeat the type name before the variable name).</p>
<h2>Other Features</h2>
<p>The new standard has also several provisions that will improve programming in many ways. Examples include new types of constants, improved initialization of objects, among others. I plan to write about some of these features in the future &#8212; stay tuned.</p>
<h2><strong>Related Articles</strong></h2>
<ul>
<li>Check my review of a book on the <a href="http://cppsource.com/2009/04/book-review-large-scale-c-software-design/">development of large-scale systems in C++</a>.</li>
<li>A discussion of <a href="http://in4mationflow.com/Cplusplus/Articles/Challenges-of-Large-Scale-C-Programming">issues in large scale C++ development</a>.</li>
</ul>
<div>
<a href="http://www.basecampHQ.com/?referrer=CARLOSOLIVEIRA"><img alt="Basecamp" border="0" height="125" src="https://affiliate.37signals.com/images/products/basecamp/banner-270x125.png" width="270" /></a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://cppsource.com/2009/04/some-features-of-the-c0x-standard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book review: Large-Scale C++ Software Design</title>
		<link>http://cppsource.com/2009/04/book-review-large-scale-c-software-design/</link>
		<comments>http://cppsource.com/2009/04/book-review-large-scale-c-software-design/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:22:30 +0000</pubDate>
		<dc:creator>carlos</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[compilation]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[large scale]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://cppsource.com/?p=8</guid>
		<description><![CDATA[The book &#8220;large-scale C++ software design&#8221; presents a clear explanation of the concepts necessary to understand large-scale C++ systems. When a project has thousands of files, it is very difficult to manage the complexity of changing code. By its very nature, C++ puts a lot of stress on the building system, and a project can [...]]]></description>
			<content:encoded><![CDATA[<p><iframe align="right" src="http://rcm.amazon.com/e/cm?t=bookdablogonb-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=0201633620&#038;md=10FE9736YVPPT7A0FBG2&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>The book &#8220;large-scale C++ software design&#8221; presents a clear explanation of the concepts necessary to understand large-scale C++ systems. When a project has thousands of files, it is very difficult to manage the complexity of changing code. By its very nature, C++ puts a lot of stress on the building system, and a project can just become extremely hard to maintain if the proper code dependencies are not taken care of.</p>
<p>In large scale C++, John Lakos provides a very thorough discussion of techniques to avoid dependencie problems in large projects. The author skips simple concepts that are commonly treated in other books, such as naming variables and other style issues. Instead, he concentrates in problems that happen only on large-scale systems.</p>
<p>Large-scale C++ was the first book to bring into discussion the issue of header files as a major source of dependencies between C++ modules. Due to the compilation model used in C++, where each file can potentially include hundreds of header files, changing one of these headers can have a large impact on other parts of your program. In fact, in C++ is not uncommon that a single change in a header files requires the recompilation of thousands of files, or even the whole project.</p>
<p>The book also discusses how to create modules that have as few dependencies as possible. This practice increases reuse of the resulting software, since a programmer doesn&#8217;t need to include hundreds of header files just to have access to a single functionality.</p>
<p>Large-scale C++ has hundreds of examples, and every concept is accompanied by sample code illustrating the concept. It is a very thorough book, and even though it is long, every page has some interesting idea.</p>
<p>You can check other reviews and information about <a href="http://www.amazon.com/gp/product/0201633620?ie=UTF8&#038;tag=bookdablogonb-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0201633620">Large-scale C++ software design</a> in its <a href="http://www.amazon.com/gp/product/0201633620?ie=UTF8&#038;tag=bookdablogonb-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0201633620">main web page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cppsource.com/2009/04/book-review-large-scale-c-software-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

