<?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>iWonder Designs &#187; Search Results  &#187;  forum</title>
	<atom:link href="http://iwonderdesigns.com/search/forum/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>http://iwonderdesigns.com</link>
	<description>A (one man) team of designers and developers specializing in web applications</description>
	<lastBuildDate>Wed, 25 May 2011 15:19:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Templates and Files</title>
		<link>http://iwonderdesigns.com/2010/12/22/templates-and-files/</link>
		<comments>http://iwonderdesigns.com/2010/12/22/templates-and-files/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 20:24:29 +0000</pubDate>
		<dc:creator>Karim</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://iwonderdesigns.com/2010/12/22/templates-and-files/</guid>
		<description><![CDATA[Something I always wondered about was why STL piles implementations into the same file as the declarations.&#160; Never had a good reason to investigate until today when my class template implementation – which was located in a separate file from the class declaration &#8211; compiled fine (seemingly) but the linker couldn’t find any of the [...]]]></description>
			<content:encoded><![CDATA[<p>Something I always wondered about was why STL piles implementations into the same file as the declarations.&#160; Never had a good reason to investigate until today when my class template implementation – which was located in a separate file from the class declaration &#8211; compiled fine (seemingly) but the linker couldn’t find any of the template class’s method implementations (needless to say I spend little or no time implementing my own template classes – just never had much of a need).&#160; But today I did and stumbled on this excellent explanation of what’s going on:</p>
<blockquote><p>To answer your initial question and to provide a condensed explanation for the reason behind your compile problem.     </p>
<p>From the point of view of the compiler, templates are not normal functions or classes. They are compiled on demand, meaning that the code of a template function is not compiled until an instantiation with specific template arguments is required. At that moment, when an instantiation is required, the compiler generates a function specifically for those arguments from the template.     </p>
<p>When projects grow it is usual to split the code of a program in different source code files. In these cases, the interface and implementation are generally separated. Taking a library of functions as example, the interface generally consists of declarations of the prototypes of all the functions that can be called. These are generally declared in a &quot;header file&quot; with a .h extension, and the implementation (the definition of these functions) is in an independent file with c++ code.     </p>
<p><strong>Because templates are compiled when required, this forces a restriction for multi-file projects: the implementation (definition) of a template class or function must be in the same file as its declaration</strong>. That means that we cannot separate the interface in a separate header file, and that we must include both interface and implementation in any file that uses the templates.      </p>
<p>Since no code is generated until a template is instantiated when required, compilers are prepared to allow the inclusion more than once of the same template file with both declarations and definitions in a project without generating linkage errors.</p>
</blockquote>
<p><a href="http://www.codingforums.com/archive/index.php/t-185375.html">Thanks saige</a></p>
]]></content:encoded>
			<wfw:commentRss>http://iwonderdesigns.com/2010/12/22/templates-and-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What?</title>
		<link>http://iwonderdesigns.com/2009/09/30/what/</link>
		<comments>http://iwonderdesigns.com/2009/09/30/what/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 20:00:27 +0000</pubDate>
		<dc:creator>Karim</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://blog.iwonderdesigns.com/2009/09/30/what/</guid>
		<description><![CDATA[via fohguild.org Posted via web from JumbleSquid]]></description>
			<content:encoded><![CDATA[<div class="posterous_bookmarklet_entry"> <img src="http://posterous.com/getfile/files.posterous.com/iwonderdesigns/mxgztgvtCGjiyCEvIoHxtuAduGdFpdIpriGBjijuswzJsqznlvBCwvccjEJf/media_httpwwwfohguildorgforumsattachmentsscreenshots95895d1229374265funnystrangerandompics24mcj1gjpg_wwpnswiboBqdjve.jpg.scaled500.jpg" width="500" height="667"/>
<div class="posterous_quote_citation">via <a href="http://www.fohguild.org/forums/attachments/screenshots/95895d1229374265-funny-strange-random-pics-24mcj1g.jpg">fohguild.org</a></div>
</p>
</div>
<p style="font-size: 10px;">  <a href="http://posterous.com">Posted via web</a>   from <a href="http://iwonderdesigns.posterous.com/what-12072">JumbleSquid</a>  </p>
]]></content:encoded>
			<wfw:commentRss>http://iwonderdesigns.com/2009/09/30/what/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

