<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>nointrigue.com &#187; Computing</title>
	<atom:link href="http://www.nointrigue.com/blog/category/computing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nointrigue.com/blog</link>
	<description>Enoch Lau&#039;s Blog</description>
	<lastBuildDate>Fri, 25 Jun 2010 16:27:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
		<item>
		<title>Optus and Telstra screwing with DNS</title>
		<link>http://www.nointrigue.com/blog/2009/11/19/optus-and-telstra-screwing-with-dns/</link>
		<comments>http://www.nointrigue.com/blog/2009/11/19/optus-and-telstra-screwing-with-dns/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 20:43:50 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[epic fail]]></category>
		<category><![CDATA[optus]]></category>
		<category><![CDATA[telstra]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=1311</guid>
		<description><![CDATA[Optus, Optus, Optus. You really like screwing over your customers right? I really didn’t appreciate having to work out why my home network printer stopped working right in the middle of exams — because you screwed with DNS to earn a few easy quid. (Same goes for you, Telstra.)
]]></description>
			<content:encoded><![CDATA[<p>Optus, Optus, Optus. You really like screwing over your customers right? I really didn’t appreciate having to work out why my home network printer stopped working right in the middle of exams — because <a href="http://forums.whirlpool.net.au/forum-replies.cfm?t=1298553">you screwed with DNS</a> to earn a few easy quid. (<a href="http://forums.whirlpool.net.au/forum-replies.cfm?t=1323971">Same goes for you, Telstra.</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/11/19/optus-and-telstra-screwing-with-dns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>IFOSS Law Review</title>
		<link>http://www.nointrigue.com/blog/2009/10/18/ifoss-law-review/</link>
		<comments>http://www.nointrigue.com/blog/2009/10/18/ifoss-law-review/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 10:57:13 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Law]]></category>
		<category><![CDATA[ifosslr]]></category>
		<category><![CDATA[journal]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=1255</guid>
		<description><![CDATA[The International Free and Open Source Software Law Review – about time, although, of course, it’s more for lawyers than FOSS enthusiasts.
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.ifosslr.org/">International Free and Open Source Software Law Review</a> – about time, although, of course, it’s more for lawyers than FOSS enthusiasts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/10/18/ifoss-law-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>The death of suitsbeta</title>
		<link>http://www.nointrigue.com/blog/2009/09/18/the-death-of-suitsbeta/</link>
		<comments>http://www.nointrigue.com/blog/2009/09/18/the-death-of-suitsbeta/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 00:31:21 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[suits]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=1171</guid>
		<description><![CDATA[When the SUITS web server went down a couple of weeks ago, the skies darkened and there was much outpouring of grief.
In the words of one committee member:

At approximately 1445 today, suitsbeta shut itself down, never to wake up again. Attempts were made to revive it by powering it up, but alas it failed to [...]]]></description>
			<content:encoded><![CDATA[<p>When the <a href="http://suits.it.usyd.edu.au/">SUITS</a> web server went down a couple of weeks ago, the skies darkened and there was much outpouring of grief.</p>
<p>In the words of one committee member:</p>
<blockquote><p>
At approximately 1445 today, suitsbeta shut itself down, never to wake up again. Attempts were made to revive it by powering it up, but alas it failed to POST. Our thoughts go out to its family and friends.</p></blockquote>
<p>Another expressed regret:</p>
<blockquote><p>It was nice knowing you suitsbeta. We’re sad that you toiled alone and in sickness for your last few months.</p></blockquote>
<p>But it was well-loved:</p>
<blockquote><p>Although I did not log into suitsbeta many times I did appreciate the machine and the contribution it made to this society. Few can claim to have sustained such continuous service to the society and its members, never asking for recognition or relief.</p></blockquote>
<p>However, death can give rise to hope:</p>
<blockquote><p>
The memory of suitsbeta’s cranky innards will live on in the cron messages, reboot requests, and database errors that pepper my email archives. May the metal be reborn and the warnings silenced.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/09/18/the-death-of-suitsbeta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>Nuffnang and Internet Explorer</title>
		<link>http://www.nointrigue.com/blog/2009/08/24/nuffnang-and-internet-explorer/</link>
		<comments>http://www.nointrigue.com/blog/2009/08/24/nuffnang-and-internet-explorer/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 09:25:36 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[nuffnang]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=990</guid>
		<description><![CDATA[Update: It turned out to be a problem with the Lightbox plugin I was using. I’ve replaced it with another plugin that provides similar functionality, and the error has now gone away. Lesson learnt: having many scripts on the same page can be a recipe for disaster. Thanks Nuffnang for helping me work through this [...]]]></description>
			<content:encoded><![CDATA[<p><em>Update: It turned out to be a problem with the Lightbox plugin I was using. I’ve replaced it with another plugin that provides similar functionality, and the error has now gone away. Lesson learnt: having many scripts on the same page can be a recipe for disaster. Thanks Nuffnang for helping me work through this issue.</em></p>
<p>I recently added a <a href="http://www.nuffnang.com.au/">Nuffnang</a> ad to the sidebar — I hope none of you mind too much!</p>
<p>Anyway, all was going well until Internet Explorer threw a spanner into the works (well, well, which browser always throws a spanner into the works?).</p>
<p>It appears that on Internet Explorer 7 and earlier (using my particular WordPress template at least), the addition of the Nuffnang ad code can cause the page to fail to load with an <a href="http://support.microsoft.com/kb/927917">Operation aborted error</a>:</p>
<p><img class="alignnone size-full wp-image-992" title="opabort" src="http://www.nointrigue.com/blog/wp-content/uploads/2009/08/opabort.png" alt="opabort" width="429" height="132" /></p>
<p>This error is particularly troublesome: after the hopelessly uninformative dialog box is dismissed, the page disappears and gets replaced by a navigation error page. (Thankfully, this hideous behaviour <a href="http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx">was changed in IE8</a>, which might explain why I didn’t pick it up earlier as that is my installed version. But it still begs the question, why do people insist on using Internet Explorer?)</p>
<p>I’ve let Nuffnang know about the potential problem, and with any luck, it will be resolved soon.</p>
<p>In the meantime, I’ve made some changes to the ad code:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:Consolas,monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- nuffnang --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:0--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--mce:1--&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- nuffnang--&gt;</span></pre></div></div>

<p>What this does is that it first checks whether the browser is Internet Explorer. If it is not, the Nuffnang script can be called upon directly. If it is Internet Explorer, an <code>iframe</code> displaying <a href="/nuffnang.html"><code>/nuffnang.html</code></a> is added to the document. <a href="/nuffnang.html"><code>/nuffnang.html</code></a> just contains a copy of the ad code as provided by Nuffnang placed into an otherwise blank HTML page.</p>
<p>Why? Isolating the Nuffnang ad code in a blank page by itself seems to avoid the error conditions as described by <a href="http://support.microsoft.com/kb/927917">KB927917</a>. But even if an error were to develop, the error would be confined to the <code>iframe</code> and the rest of the page can still be displayed.</p>
<p>If you’re having similar difficulties, give the above a go and see whether it works for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/08/24/nuffnang-and-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>GPlates</title>
		<link>http://www.nointrigue.com/blog/2009/08/11/gplates/</link>
		<comments>http://www.nointrigue.com/blog/2009/08/11/gplates/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 01:50:18 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gplates]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=819</guid>
		<description><![CDATA[I recently started doing software development on a casual basis for GPlates, at the School of Geosciences, University of Sydney. Think back to high-school science class where you learnt about Pangaea and Gondwanaland and how the Earth’s tectonic plates have ever-so-slowly shifted over millions of years. GPlates is software that allows scientists to “wind the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started doing software development on a casual basis for <a href="http://www.gplates.org/">GPlates</a>, at the School of Geosciences, University of Sydney. Think back to high-school science class where you learnt about Pangaea and Gondwanaland and how the Earth’s tectonic plates have ever-so-slowly shifted over millions of years. GPlates is software that allows scientists to “wind the clock back” on these plate movements and visualise what the Earth might have looked like all these years ago. It’s open-source, so if you’re curious, grab a copy and play with it.</p>
<p>I’m quite glad to have met the GPlates team. It’s difficult, I think, to find quality software engineering in Australia, and GPlates development is led by a bunch of developers who are passionate about writing quality, well-designed, best-practice C++ code. It’s certainly not your average in-house or academic research software. And it sure is more intellectually safisfying than working in corporate IT.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/08/11/gplates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>Google Wave sandbox account</title>
		<link>http://www.nointrigue.com/blog/2009/06/18/google-wave-sandbox-account/</link>
		<comments>http://www.nointrigue.com/blog/2009/06/18/google-wave-sandbox-account/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 08:50:45 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[google wave]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=735</guid>
		<description><![CDATA[I just got my Google Wave developer sandbox account! I can’t wait to play with it, but I think I’m going to have to put my excitement on ice until I finish my exams in a week’s time. Boo.
]]></description>
			<content:encoded><![CDATA[<p>I just got my <a href="http://wave.google.com/">Google Wave</a> developer sandbox account! I can’t wait to play with it, but I think I’m going to have to put my excitement on ice until I finish my exams in a week’s time. Boo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/06/18/google-wave-sandbox-account/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>Singletons in C++</title>
		<link>http://www.nointrigue.com/blog/2009/05/18/singletons-in-c/</link>
		<comments>http://www.nointrigue.com/blog/2009/05/18/singletons-in-c/#comments</comments>
		<pubDate>Mon, 18 May 2009 04:21:30 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Asides]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=724</guid>
		<description><![CDATA[To kill a singleton: I found this to be a useful discussion on how to write a singleton class in C++ that ensures the singleton is properly destroyed (for even multithreaded applications).
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.research.ibm.com/designpatterns/pubs/ph-jun96.txt">To kill a singleton</a>: I found this to be a useful discussion on how to write a singleton class in C++ that ensures the singleton is properly destroyed (for even multithreaded applications).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/05/18/singletons-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>Forwarding University of Sydney student email</title>
		<link>http://www.nointrigue.com/blog/2009/05/07/forwarding-university-of-sydney-student-email/</link>
		<comments>http://www.nointrigue.com/blog/2009/05/07/forwarding-university-of-sydney-student-email/#comments</comments>
		<pubDate>Wed, 06 May 2009 18:22:54 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[epic fail]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[sydney university]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=702</guid>
		<description><![CDATA[Update: Thank you to all who have contributed to the discussion below. For the impatient, here is a summary of what you might like to do:

If you hate Sydney Mail, fear not: you have options. 
To redirect your Sydney Mail email to another email account, you can either a) use a “redirect” rule in Sydney [...]]]></description>
			<content:encoded><![CDATA[<div style="border: 1px solid black; padding: 1em; margin-bottom: 1em; line-height: 150%"><em><strong>Update: </strong>Thank you to all who have contributed to the discussion below. For the impatient, here is a summary of what you might like to do:</em></p>
<ul>
<li>If you hate Sydney Mail, fear not: you have options.<em> </em></li>
<li>To redirect your Sydney Mail email to another email account, you can either a) <a href="http://www.usyd.edu.au/ict/switch/SydneyMail/forwardemail.shtml">use a “redirect” rule in Sydney Mail</a> or b) get your email client (such as Gmail) to pick it up via POP3 (for this, see the main post below). Both a) and b) do the job.</li>
<li>To send email from within Gmail as if you were sending it from Sydney Mail, add your Sydney Mail address under the Addresses tab in Settings in Gmail.</li>
<li>However, some recipients, such as those using Outlook, may see that the sender of your email is “xyz@gmail.com on behalf of abcd1234@uni.sydney.edu.au”. If you don’t like this, you can fix this by <a href="http://gmailblog.blogspot.com/2009/07/send-mail-from-another-address-without.html">getting Gmail to send email via SMTP</a>. To find out the address of the SMTP server, see <a href="http://www.usyd.edu.au/ict/switch/pdf/email/EML010Othermailservers.pdf">these instructions</a>.</li>
</ul>
</div>
<p>“Sydney Mail is a new and significantly improved student email service,” announced the email from the university proudly.</p>
<p>The truth is that the university has delivered something that’s <em>better</em>, but is rather deficient in its own right: they’ve outsourced email to Microsoft so it’s all now run off Outlook Web Access. I could go on and on about why I would never use it, but I’ll just show you how to avoid using it.</p>
<p>The existing email system allows you to forward to a personal email address, and the university <a href="http://www.usyd.edu.au/ict/switch/SydneyMail/forwardemail.shtml">provides instructions</a> for how to do it on the new system. <em>Don’t follow those instructions!</em> It is true that email will be forwarded from Outlook to your personal email but what happens is that the emails are <em>literally forwarded</em>! If Bob sends you an email, when it pops up in your personal email, the From field will show your university email as opposed to Bob, which is incredibly inconvenient.</p>
<p>The solution? Get your mail client to retrieve mail from Outlook via POP3. If you’re using Gmail like me, go to Settings &gt; Accounts. Look for the “Get mail from other accounts” section and click the “Add a mail account you own” link. A window will then pop up; try the following settings:</p>
<p><img class="alignnone size-full wp-image-703" src="http://www.nointrigue.com/blog/wp-content/uploads/2009/05/sydneymail.png" alt="Settings" width="460" height="204" /></p>
<p>Email sent to your university email won’t get forwarded instantly like it used to, but it’s a much better solution than the one offered by the university.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/05/07/forwarding-university-of-sydney-student-email/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>C++ maps exercise: answer</title>
		<link>http://www.nointrigue.com/blog/2009/04/25/c-maps-exercise-answer/</link>
		<comments>http://www.nointrigue.com/blog/2009/04/25/c-maps-exercise-answer/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 12:17:06 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=663</guid>
		<description><![CDATA[Here are the solutions to the C++ maps exercise I posed in this post.
The first set of problems relates to the fact that the Employee class has no default constructor. Here’s why. In the line

	id&#91;0&#93; = Employee&#40;&#34;John Smith&#34;&#41;;

what doesn’t happen is that the key 0 gets associated with the new Employee object you just created. [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the solutions to the C++ maps exercise I posed in <a href="http://www.nointrigue.com/blog/2009/04/18/c-maps-an-exercise/">this post</a>.</p>
<p>The first set of problems relates to the fact that the Employee class has no default constructor. Here’s why. In the line</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:Consolas,monospace;">	id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> Employee<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;John Smith&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>what <em>doesn’t</em> happen is that the key 0 gets associated with the new Employee object you just created. What <em>does</em> happen is that the <code>id[0]</code> part tries to default initialise an Employee object, and then assign using <code>operator=</code> the Employee object you created on the right hand side. That’s all fine if you have a default constructor, but our Employee class doesn’t have one (because I’ve defined another constructor but not the default constructor). Without changing the class definition to add a default constructor, you will need to explicitly insert the key-value pair into the map, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:Consolas,monospace;">	id.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>make_pair<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, Employee<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;John Smith&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>But what about this line?</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:Consolas,monospace;">	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>.<span style="color: #007788;">name</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span></pre></div></div>

<p>Surely, it wouldn’t be trying to call the default constructor here, because I am merely retrieving the value of <code>id[0]</code>, which I know has already been constructed? But at compile time, how would the compiler know whether the call to <code>id[0]</code> will result in a new object being constructed or not even if you do? To get around this problem, you’ll have to go around the long way:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:Consolas,monospace;">	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> id.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second.<span style="color: #007788;">name</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span></pre></div></div>

<p>So the moral of the story is <em>write a default constructor</em> (if it makes sense to do so)! Note that <code>operator[]</code> is also unavailable when you have a const map. (Why?)</p>
<p>For the second lot of problems, the root of the problem is that you are using Employee as the key type of the map. You can only use a class as a key if you can order objects of that class, so you’ll have to write an <code>operator&lt;</code> for Employee.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/04/25/c-maps-exercise-answer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
		<item>
		<title>C++ maps: an exercise</title>
		<link>http://www.nointrigue.com/blog/2009/04/18/c-maps-an-exercise/</link>
		<comments>http://www.nointrigue.com/blog/2009/04/18/c-maps-an-exercise/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 09:08:58 +0000</pubDate>
		<dc:creator>Enoch Lau</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[tutoring]]></category>

		<guid isPermaLink="false">http://www.nointrigue.com/blog/?p=643</guid>
		<description><![CDATA[Why doesn’t the following code compile? Without changing the definition of the struct Employee, can you make it compile so that it does what it’s meant to do?

#include &#60;iostream&#62;
#include &#60;map&#62;
#include &#60;string&#62;
&#160;
using namespace std;
&#160;
struct Employee
&#123;
	string name;
	Employee&#40;const string&#38; s&#41; : name&#40;s&#41; &#123; &#125;
&#125;;
&#160;
int main&#40;&#41;
&#123;
	map&#60;int, Employee&#62; id;
	id&#91;0&#93; = Employee&#40;&#34;John Smith&#34;&#41;;
	id&#91;1&#93; = Employee&#40;&#34;Mary Jane&#34;&#41;;
	cout &#60;&#60; id&#91;0&#93;.name &#60;&#60; endl;
&#160;
	map&#60;Employee, int&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Why doesn’t the following code compile? <em>Without changing the definition of the struct Employee</em>, can you make it compile so that it does what it’s meant to do?</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:Consolas,monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;map&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">struct</span> Employee
<span style="color: #008000;">&#123;</span>
	string name<span style="color: #008080;">;</span>
	Employee<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> string<span style="color: #000040;">&amp;</span> s<span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> name<span style="color: #008000;">&#40;</span>s<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	map<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>, Employee<span style="color: #000080;">&gt;</span> id<span style="color: #008080;">;</span>
	id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> Employee<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;John Smith&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> Employee<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Mary Jane&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>.<span style="color: #007788;">name</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	map<span style="color: #000080;">&lt;</span>Employee, <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> id2<span style="color: #008080;">;</span>
	Employee a<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;A&quot;</span><span style="color: #008000;">&#41;</span>, b<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;B&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	id2<span style="color: #008000;">&#91;</span>a<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
	id2<span style="color: #008000;">&#91;</span>b<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">200</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><a href="http://www.nointrigue.com/blog/2009/04/25/c-maps-exercise-answer/">Answers here.</a></p>
<p>(I gave this exercise to my C++ students a couple of weeks ago.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nointrigue.com/blog/2009/04/18/c-maps-an-exercise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/2.5/au/</creativeCommons:license>
	</item>
	</channel>
</rss>
