<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5883865168597393160</id><updated>2011-12-11T00:14:38.399+05:30</updated><category term='WebApp'/><category term='Mobile'/><category term='WebRuntime'/><category term='QtWebKit'/><category term='Nokia'/><category term='Bjarne Stroustrup'/><category term='Digest Authentication'/><category term='Library'/><category term='DLL'/><category term='AJAX'/><category term='RTTI'/><category term='MoFuse'/><category term='Windows'/><category term='Security'/><category term='WebKit'/><category term='constructors'/><category term='dynamic_cast'/><category term='Symbian'/><category term='BackwardCompatibility'/><category term='Web'/><category term='Ordinals'/><category term='C++'/><category term='Overloading'/><category term='XHR'/><category term='PIMPL'/><category term='operator new'/><category term='Firefox'/><category term='BMTC'/><category term='Linux'/><category term='GStreamer'/><category term='Smart Pointers'/><category term='QtMobility'/><category term='Qt'/><category term='Widget'/><category term='Ubuntu'/><category term='Apache'/><category term='WRT'/><category term='SVN'/><category term='Android'/><category term='Video'/><category term='Blog'/><category term='HTML5'/><category term='Basic Authentication'/><category term='WebServer'/><title type='text'>Prash's Tech Blog</title><subtitle type='html'>Let's Geek!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://prashanth-cpp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4139510315863242613</id><published>2011-05-25T18:31:00.003+05:30</published><updated>2011-05-25T18:36:31.025+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='BMTC'/><category scheme='http://www.blogger.com/atom/ns#' term='WebKit'/><category scheme='http://www.blogger.com/atom/ns#' term='Android'/><title type='text'>BMTC &amp; Android</title><content type='html'>&lt;p&gt;Recently, I noticed interactive display panels on &lt;a href="http://www.bmtcinfo.com/site/BSBusServicesDetails.jsp?bsserviceid=1"&gt;BMTC - Vayu Vajra (BIA) Volvo bus&lt;/a&gt;, while commuting to office (Hebbal to Marathhalli). I’m really excited to say that these are powered by Google’s Android Operating System.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_ZmriMFhfr-Y/Tdz9r7MGKjI/AAAAAAAAAdw/J50Yp8GjpFk/s1600-h/1%5B2%5D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://lh5.ggpht.com/_ZmriMFhfr-Y/Tdz9s4tt26I/AAAAAAAAAd0/kpsrCzt34qw/1_thumb.png?imgmax=800" width="244" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Good part is, it includes a "Webkit" browser for free internet browsing while you travel. What else you want when you are stuck in traffic? :)&lt;/p&gt;  &lt;p&gt;I could confirm that its using Android OS and Webkit browser by examining the UserAgent: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Mozilla/5.0(Linux; U; Android 2.1-update1; en-us; Generic Build/ECLAIR) AppleWebkit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;See below snapshot.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ZmriMFhfr-Y/Tdz9toDljZI/AAAAAAAAAd4/y-oAb1sJYT4/s1600-h/2%5B3%5D.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto 5px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="2" border="0" alt="2" src="http://lh4.ggpht.com/_ZmriMFhfr-Y/Tdz9uDPXSQI/AAAAAAAAAd8/gUnTygqA0V8/2_thumb.jpg?imgmax=800" width="244" height="139" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Along with the in-built browser, it also lists few useful apps - Youtube, facebook, Sudoku, Weather, Stocks, News etc.&lt;/p&gt;  &lt;p&gt;For me, these apps looks to be web-apps which are non-native and not even Java based.&lt;/p&gt;  &lt;p&gt;Advertising is another interesting aspect.  &lt;br /&gt;The lower part of the display has local retailer advertisements. BMTC may be earning a good revenue out of it. :)&lt;/p&gt;  &lt;p&gt;Overall experience of using internet on BMTC Vayu Vajra was awesome! I'm really amazed by abilities of Android as a platform. Its not just phone anymore. &lt;/p&gt;  &lt;p&gt;You may not be surprised to see these devices one day in your car. :) &lt;br /&gt;I'll wait for that day!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4139510315863242613?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4139510315863242613' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4139510315863242613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4139510315863242613'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2011/05/bmtc-android.html' title='BMTC &amp;amp; Android'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ZmriMFhfr-Y/Tdz9s4tt26I/AAAAAAAAAd0/kpsrCzt34qw/s72-c/1_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4792102448977312224</id><published>2010-10-31T02:07:00.005+05:30</published><updated>2010-10-31T15:20:13.560+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML5'/><category scheme='http://www.blogger.com/atom/ns#' term='WebApp'/><title type='text'>The Age of ‘WebApps’</title><content type='html'>&lt;p&gt;Looks like there is a big paradigm shift from ‘native’ apps to so-called ‘&lt;a href="http://en.wikipedia.org/wiki/Web_application" target="_blank"&gt;WebApps&lt;/a&gt;’ nowadays! &lt;/p&gt;  &lt;p&gt;Listing the WebApps which I personally use in daily life and like the most. &lt;/p&gt;  &lt;p&gt;Do you come across any? Let me know!&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="393"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Dropbox" href="http://www.dropbox.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="dropbox_logo_home" border="0" alt="dropbox_logo_home" src="http://lh4.ggpht.com/_ZmriMFhfr-Y/TMx-3ws4hJI/AAAAAAAAAZ0/SlrS0yQXlM4/dropbox_logo_home%5B3%5D.png?imgmax=800" width="244" height="66" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Store, Sync, Share files online.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Clipperz - Password manager" href="http://www.clipperz.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="password_manager_clipperz_logo" border="0" alt="password_manager_clipperz_logo" src="http://lh6.ggpht.com/_ZmriMFhfr-Y/TMx-4nujP7I/AAAAAAAAAZ4/A5cFBHwWX_k/password_manager_clipperz_logo%5B3%5D.png?imgmax=800" width="244" height="94" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Password Manager.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Remember The Milk" href="http://www.rememberthemilk.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="rtm_logo2" border="0" alt="rtm_logo2" src="http://lh5.ggpht.com/_ZmriMFhfr-Y/TMx-5b6TeeI/AAAAAAAAAZ8/8q4_mh6vD_o/rtm_logo2%5B3%5D.png?imgmax=800" width="192" height="87" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;To-Do list manager.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="EverNote" href="http://www.evernote.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="evernote_logo" border="0" alt="evernote_logo" src="http://lh6.ggpht.com/_ZmriMFhfr-Y/TMx-7NWtQkI/AAAAAAAAAaA/lKRfnaJ4ewo/evernote_logo%5B3%5D.jpg?imgmax=800" width="224" height="179" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Remember everything on any device.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Meebo" href="http://www.meebo.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="meebo-logo" border="0" alt="meebo-logo" src="http://lh5.ggpht.com/_ZmriMFhfr-Y/TMyBfihGXKI/AAAAAAAAAaE/1DJ-hbTjSHI/meebo-logo%5B3%5D.jpg?imgmax=800" width="244" height="107" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Instant messaging program which supports multiple IM services.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="TuneWiki" href="http://www.tunewiki.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tunewiki" border="0" alt="tunewiki" src="http://lh3.ggpht.com/_ZmriMFhfr-Y/TMyBiCEiCAI/AAAAAAAAAaI/bwK5MeCPzGg/tunewiki%5B1%5D.jpg?imgmax=800" width="244" height="151" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Creates social media players for cellphones and handheld devices with huge library of lyrics.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Read it Later" href="http://readitlaterlist.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ril" border="0" alt="ril" src="http://lh4.ggpht.com/_ZmriMFhfr-Y/TMyBlpqJLNI/AAAAAAAAAaM/58dsspmCI9g/ril%5B3%5D.png?imgmax=800" width="244" height="47" /&gt;&lt;/a&gt;&lt;a title="Remember The Milk" href="http://www.rememberthemilk.com/" target="_blank"&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Save Pages to Read Later. Offline reading!&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Youtube" href="http://youtube.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="youtube" border="0" alt="youtube" src="http://lh5.ggpht.com/_ZmriMFhfr-Y/TMyBnKXsTqI/AAAAAAAAAaQ/RcjU-54Ox88/youtube%5B3%5D.png?imgmax=800" width="183" height="131" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Web videos!&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Google Reader" href="http://www.google.com/reader/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="google_reader" border="0" alt="google_reader" src="http://lh6.ggpht.com/_ZmriMFhfr-Y/TMyBq15GORI/AAAAAAAAAak/H4_HAZC4ONc/google_reader%5B1%5D.jpg?imgmax=800" width="244" height="91" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Great feeds reader from Google.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Twitter" href="http://twitter.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="twitter-logo(1)" border="0" alt="twitter-logo(1)" src="http://lh6.ggpht.com/_ZmriMFhfr-Y/TMyB2ICFO7I/AAAAAAAAAa8/8wvPxk3UBF8/twitter-logo%281%29_thumb.jpg?imgmax=800" width="244" height="103" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Twitter!&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Wikipedia" href="http://en.wikipedia.org/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="wikipedia" border="0" alt="wikipedia" src="http://lh5.ggpht.com/_ZmriMFhfr-Y/TMyBsqYOnWI/AAAAAAAAAao/yhu3sJxyyhk/wikipedia%5B1%5D.jpg?imgmax=800" width="204" height="244" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Wiki.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Delicious" href="http://www.delicious.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="floor_planner" border="0" alt="floor_planner" src="http://lh4.ggpht.com/_ZmriMFhfr-Y/TMyBn2P89BI/AAAAAAAAAaU/-Kon8CPj1QY/floor_planner%5B2%5D.jpg?imgmax=800" width="244" height="80" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Bookmark manager.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Foursquare" href="http://foursquare.com/" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="foursquare_logo" border="0" alt="foursquare_logo" src="http://lh4.ggpht.com/_ZmriMFhfr-Y/TMyBvkrpQtI/AAAAAAAAAas/uQYQY5XnU-k/foursquare_logo%5B5%5D.jpg?imgmax=800" width="244" height="103" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td width="117"&gt;Geo-tagging.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Floor Planner" href="http://www.floorplanner.com/" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="floor_planner" border="0" alt="floor_planner" src="http://lh3.ggpht.com/_ZmriMFhfr-Y/TM07oDWldYI/AAAAAAAAAbE/5fwwzRT0wjk/floor_planner%5B1%5D.jpg?imgmax=800" width="244" height="80" /&gt;&lt;/a&gt; &lt;/td&gt;        &lt;td width="117"&gt;         &lt;p&gt;Create floor plans, house plans and home plans ‘online’.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="274"&gt;&lt;a title="Facebook" href="http://facebook.com" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="facebook" border="0" alt="facebook" src="http://lh3.ggpht.com/_ZmriMFhfr-Y/TM071AwFqPI/AAAAAAAAAbI/TAJJs90kYGI/facebook%5B4%5D.jpg?imgmax=800" width="244" height="94" /&gt;&lt;/a&gt; &lt;/td&gt;        &lt;td width="117"&gt;facebook!&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4792102448977312224?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4792102448977312224' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4792102448977312224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4792102448977312224'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/10/age-of-webapps.html' title='The Age of ‘WebApps’'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_ZmriMFhfr-Y/TMx-3ws4hJI/AAAAAAAAAZ0/SlrS0yQXlM4/s72-c/dropbox_logo_home%5B3%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-5793658397207657492</id><published>2010-10-24T10:18:00.003+05:30</published><updated>2010-10-25T23:52:37.661+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='QtMobility'/><category scheme='http://www.blogger.com/atom/ns#' term='GStreamer'/><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><title type='text'>no service found for - "com.nokia.qt.mediaplayer"</title><content type='html'>Of late, I was trying to build QtMobility on Ubuntu, specifically experimenting with QtMultimedia feature set.&lt;br /&gt;&lt;br /&gt;In the process, I stumbled on this (not so) strange issue which frustrated me for a log time. I was using Qt4.7 + QtMobility v1.1.0 Beta.&lt;br /&gt;&lt;br /&gt;Building QtMobility was not an issue. However, when I tried to play a multimedia content in demo/player app , it just couldn't play it  complaining :&lt;br /&gt;&lt;blockquote&gt;no service found for - "com.nokia.qt.mediaplayer"&lt;/blockquote&gt;It was clearly a mistake of mine not having a look at the 'configure' warning messages :&lt;br /&gt;&lt;blockquote&gt; Reading /home/pranaray/qt-mobility-opensource-src-1.1.0-beta2/plugins/multimedia/multimedia.pro&lt;br /&gt;Project MESSAGE: QtMultiMedia checking for gstreamer...&lt;br /&gt;Package gstreamer-0.10 was not found in the pkg-config search path.&lt;br /&gt;Perhaps you should add the directory containing `gstreamer-0.10.pc' to the PKG_CONFIG_PATH environment variable&lt;br /&gt;No package 'gstreamer-0.10' found&lt;br /&gt;Package gstreamer-base-0.10 was not found in the pkg-config search path.&lt;br /&gt;Perhaps you should add the directory containing `gstreamer-base-0.10.pc' to the PKG_CONFIG_PATH environment variable&lt;br /&gt;No package 'gstreamer-base-0.10' found&lt;br /&gt;Package gstreamer-interfaces-0.10 was not found in the pkg-config search path.&lt;br /&gt;Perhaps you should add the directory containing `gstreamer-interfaces-0.10.pc' to the PKG_CONFIG_PATH environment variable&lt;br /&gt;No package 'gstreamer-interfaces-0.10' found&lt;br /&gt;Package gstreamer-audio-0.10 was not found in the pkg-config search path.&lt;br /&gt;Perhaps you should add the directory containing `gstreamer-audio-0.10.pc' to the PKG_CONFIG_PATH environment variable&lt;br /&gt;No package 'gstreamer-audio-0.10' found&lt;br /&gt;Package gstreamer-video-0.10 was not found in the pkg-config search path.&lt;br /&gt;Perhaps you should add the directory containing `gstreamer-video-0.10.pc' to the PKG_CONFIG_PATH environment variable&lt;br /&gt;No package 'gstreamer-video-0.10' found&lt;/blockquote&gt;The message was clearly warning about the missing gstreamer library packages.&lt;br /&gt;I had to install &lt;span style="font-style: italic;"&gt;libgstreamer0.10-dev&lt;/span&gt; &amp;amp; &lt;span style="font-style: italic;"&gt;libgstreamer-plugins-base0.10-dev&lt;/span&gt; packages to resolve the issue.&lt;br /&gt;&lt;blockquote&gt;sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev&lt;br /&gt;&lt;/blockquote&gt;I also installed few additional gstreamer plugins along with the above said packages to be able to play mp3 and other media content formats.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-5793658397207657492?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=5793658397207657492' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/5793658397207657492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/5793658397207657492'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/10/no-service-found-for.html' title='no service found for - &quot;com.nokia.qt.mediaplayer&quot;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-1642744128825366526</id><published>2010-08-24T19:36:00.002+05:30</published><updated>2010-08-24T21:43:00.668+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='XHR'/><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='Widget'/><category scheme='http://www.blogger.com/atom/ns#' term='Firefox'/><title type='text'>Bypassing Same-Origin policy on Firefox.</title><content type='html'>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Same_origin_policy" target="_blank"&gt;Same-origin policy&lt;/a&gt; is an essential feature implemented in most of the modern browsers to shield against malicious scripts execution. It simply blocks javascripts belong to domains other than the one which is currently being executed.&lt;/p&gt;  &lt;p&gt;However, for development and testing of mash-ups, web apps or widgets, its sometimes required to disable this, so that a local javascript of my widget could reach Twitter or Foursquare webserver to pull the data via AJAX. &lt;/p&gt;  &lt;p&gt;Firefox as a leader desktop browser simply block such attempts denying the cross origin AJAX requests.&lt;/p&gt;  &lt;p&gt;Fortunately, Firefox’s settings are configurable and it allows us to disable such restrictions so that it can bypass the Same-origin policy.&lt;/p&gt;  &lt;p&gt;Here is a brief summary of what I discovered for achieving this. Special thanks to &lt;a href="http://twitter.com/raghava"&gt;Raghava&lt;/a&gt; for helping me out to reach to it.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step-1&lt;/strong&gt;  &lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Launch Firefox browser, navigate to "about:config". &lt;/li&gt;&lt;li&gt;Set the property "&lt;i&gt;security.fileuri.strict_origin_policy&lt;/i&gt;" to “&lt;i&gt;false&lt;/i&gt;”&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step-2&lt;/strong&gt;  &lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the javascript by add this line before creating any XHR request:&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;netscape.security.PrivilegeManager.enablePrivilege(”UniversalBrowserRead”); &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Example : &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;// Enable Universal Browser Read   &lt;br /&gt;try{ &lt;/p&gt;    &lt;p&gt;      netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); &lt;/p&gt;    &lt;p&gt;}   &lt;br /&gt;catch(e){ &lt;/p&gt;    &lt;p&gt;     alert(e); &lt;/p&gt;    &lt;p&gt;}    &lt;/p&gt;    &lt;p&gt;// create XmlHttpRequest Object   &lt;br /&gt;var xmlhttp = new XMLHttpRequest(); &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;That's it! You are now all set to access any cross origin resource from a local web app running on Firefox.&lt;/p&gt;&lt;p&gt;Please remember to revert this setting back so that your web is back to safe mode :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-1642744128825366526?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=1642744128825366526' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1642744128825366526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1642744128825366526'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/08/bypassing-same-origin-policy-on-firefox.html' title='Bypassing Same-Origin policy on Firefox.'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-2911555089451710293</id><published>2010-07-11T18:26:00.003+05:30</published><updated>2010-07-11T19:48:08.255+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='QtWebKit'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='WebKit'/><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><title type='text'>Building QtWebKit on Windows – Few common issues</title><content type='html'>&lt;p&gt;In continuation to my &lt;a href="http://prashanth-cpp.blogspot.com/2010/07/building-qtwebkit-on-windows.html" target="_blank"&gt;last blog entry&lt;/a&gt;, here I’m trying to capture few common problems that I encountered along with possible solutions for them, in the process of building QtWebKit for windows.&lt;/p&gt;  &lt;p&gt;Listing out issues and followed by possible solution for them:&lt;/p&gt;  &lt;h4&gt;1. ERROR: qmake missing but required to build WebKit.&lt;/h4&gt;  &lt;p&gt;Make sure QTDIR env variable is set and PATH variable includes path to Qt bin folder.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;set QTDIR=C:\Qt\4.6.3&lt;/p&gt;    &lt;p&gt;set PATH=%PATH%;%QTDIR%\bin;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;2. ERROR: flex, bison, gperf missing but required to build WebKit.&lt;/h4&gt;  &lt;p&gt;Have you installed GNUWin32 tools? Also, include GNUWin32 bin path under PATH env variable. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;set PATH=%PATH%;C:\GnuWin32\bin;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;3. 'nmake' is not recognized as an internal or external command&lt;/h4&gt;  &lt;p&gt;Make sure you have installed MS Visual Studio. Also try running the webkit build script from within &lt;em&gt;Visual Studio 2008 Command Prompt.&lt;/em&gt;&lt;/p&gt;  &lt;h4&gt;4. Failed to generate WebCore's derived sources!Can't locate Switch.pm in @INC&lt;/h4&gt;  &lt;p&gt;Is Active Perl installed? Active Perl v5.10 or higher is required. Update PATH env variable with perl bin folder paths.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;set PATH=C:\Perl\site\bin;C:\Perl\bin;%PATH%&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;5. Cannot open include file: 'windows.h': No such file or directory &lt;/h4&gt;  &lt;p&gt;Microsoft Platform SDK need to be installed. INCLUDE and LIB env variables need to be updated.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;set INCLUDE=%INCLUDE%;C:\Program Files\Microsoft SDKs\Windows\v6.0\Include&lt;/p&gt;    &lt;p&gt;set LIB=%LIB%;C:\Program Files\Microsoft SDKs\Windows\v6.0\Lib&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;6. JavaScriptCore\DerivedSources\chartables.c (13) : error C2466: cannot allocate an array of constant size 0&lt;/h4&gt;  &lt;p&gt;This issue arises because of usage of wrong version of perl to generate derived sources.&lt;/p&gt;  &lt;p&gt;To solve this issue, we need to install Active Perl v5.10 and regenerate derived sources. For regenerating the derived sources, delete the ‘&lt;em&gt;WebKitBuild&lt;/em&gt;’ folder and restart the build by launching the ‘&lt;em&gt;build-webkit&lt;/em&gt;’ script again.&lt;/p&gt;  &lt;h4&gt;7. LINK : fatal error LNK1210: exceeded internal ILK size limit; link with /INCREMENTAL:NO&lt;/h4&gt;  &lt;p&gt;Not sure why visual studio crib with such a linker error. As a quick solution, we need to disable incremental linking. &lt;/p&gt;  &lt;p&gt;Update &lt;em&gt;webkit.pri&lt;/em&gt; by adding linker flag to disable incremental linking:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;QMAKE_LFLAGS += /INCREMENTAL:NO&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Restart the build by launching the ‘&lt;em&gt;build-webkit’&lt;/em&gt; script again. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-2911555089451710293?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=2911555089451710293' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2911555089451710293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2911555089451710293'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/07/building-qtwebkit-on-windows-few-common.html' title='Building QtWebKit on Windows – Few common issues'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-3507696848116434170</id><published>2010-07-11T18:16:00.002+05:30</published><updated>2010-07-11T19:47:56.728+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='QtWebKit'/><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='WebKit'/><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><title type='text'>Building QtWebKit on Windows</title><content type='html'>&lt;p&gt;Intention of this and the following blog entries is to record my experiences while building QtWebKit on Windows with MS Visual Studio 2008. I’ve tried to gather few common issues and solutions for them which I came across in the process of compilation.&lt;/p&gt;  &lt;h4&gt;Which compiler?&lt;/h4&gt;  &lt;p&gt;I opted for Microsoft Visual Studio 2008 as I had it already installed on my laptop. &lt;/p&gt;  &lt;p&gt;However, &lt;a href="http://trac.webkit.org/wiki/BuildingQtOnWindows" target="_blank"&gt;QtWebKit building instructions&lt;/a&gt; indicate that we can use either MSVS or MinGW. &lt;/p&gt;  &lt;p&gt;Note that, rest of this article only talks about using MS Visual Studio (nmake) as the compiler. If you are willing to choose MinGW, please follow instructions &lt;a href="http://webkit.sed.hu/blog/20091027/building-qtwebkit-windows" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;Windows Platform SDK&lt;/h4&gt;  &lt;p&gt;Download and install Windows Platform SDK. Make sure INCLUDE env variable has the SDK include path:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;ex : C:\Program Files\Microsoft SDKs\Windows\v6.0\Include&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;and LIB env variable includes SDK lib path. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;ex : C:\Program Files\Microsoft SDKs\Windows\v6.0\Lib&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;Active Perl v5.10&lt;/h4&gt;  &lt;p&gt;Install Active Perl later than v5.10 from &lt;a href="http://www.activestate.com/activeperl" target="_blank"&gt;here&lt;/a&gt;. Ensure PATH variable includes:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;C:\Perl\bin;C:\Perl\site\bin&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;Qt for Windows SDK&lt;/h4&gt;  &lt;p&gt;&lt;font color="#333333"&gt;Download and install latest available Qt for windows from &lt;a href="http://qt.nokia.com/downloads"&gt;http://qt.nokia.com/downloads&lt;/a&gt;&lt;/font&gt;&lt;font color="#333333"&gt;. Qt can either be downloaded as an SDK or as precompiled binary set. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;When I downloaded SDK, I noticed that the SDK binaries were compiled with MinGW. This means, its incompatible with my MSVC compiler. So, I had to rebuild Qt source from scratch after installing Qt SDK.&lt;/p&gt;  &lt;p&gt;As an alternative to this approach, we can download and install Qt binaries which are precompiled with MSVC.&lt;/p&gt;  &lt;p&gt;Luckily Qt provides prebuilt binaries compiled with both MinGW and MSVC-2008. You can choose either of that, based on the compiler you are using.&lt;/p&gt;  &lt;p&gt;Ensure QTDIR env variable is created and pointing to Qt install folder.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;ex : QTDIR=C:\Qt\4.6.3&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Also, PATH variable need to include the Qt binary path:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;C:\Qt\4.6.3\bin&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;GNUWin32 tools&lt;/h4&gt;  &lt;p&gt;&lt;font color="#333333"&gt;Download and install following &lt;a href="http://gnuwin32.sourceforge.net/packages.html" target="_blank"&gt;GNUWin32 tools&lt;/a&gt; :&lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://gnuwin32.sourceforge.net/downlinks/bison.php"&gt;Bison&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://gnuwin32.sourceforge.net/downlinks/gperf.php"&gt;GPerf&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://gnuwin32.sourceforge.net/downlinks/flex.php"&gt;Flex&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://gnuwin32.sourceforge.net/downlinks/libiconv.php"&gt;LibIconv&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Include install path under PATH env variable (ex: C:\GnuWin32\bin)&lt;/p&gt;  &lt;h4&gt;Checking out WebKit source&lt;/h4&gt;  &lt;p&gt;Check out source from WebKit SVN trunk &lt;a href="http://svn.webkit.org/repository/webkit/trunk"&gt;http://svn.webkit.org/repository/webkit/trunk&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I experienced a glitch while checking out webkit repository. Have a look at my &lt;a href="http://prashanth-cpp.blogspot.com/2010/07/excluding-folders-while-checking-out.html" target="_blank"&gt;previous blog entry&lt;/a&gt; for more info on that.&lt;/p&gt;  &lt;h4&gt;Building QtWebkit&lt;/h4&gt;  &lt;p&gt;Now, we are ready with all the pre-requisites. To build QtWebKit, we need to run &lt;em&gt;build-webkit&lt;/em&gt; script passing &lt;em&gt;–-qt&lt;/em&gt; and &lt;em&gt;-–debug&lt;/em&gt; or &lt;em&gt;--release&lt;/em&gt; parameters.&lt;/p&gt;  &lt;p&gt;Following script execution builds the release version of QtWebKit binaries:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;perl WebKitTools\Scripts\build-webkit --qt --release&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;for debug version of binaries :&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;perl WebKitTools\Scripts\build-webkit --qt --debug&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;References&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://trac.webkit.org/wiki/BuildingOnWindows"&gt;http://trac.webkit.org/wiki/BuildingOnWindows&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://trac.webkit.org/wiki/BuildingQtOnWindows"&gt;http://trac.webkit.org/wiki/BuildingQtOnWindows&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://webkit.sed.hu/blog/20091027/building-qtwebkit-windows"&gt;http://webkit.sed.hu/blog/20091027/building-qtwebkit-windows&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://webkit.org/building/build.html"&gt;http://webkit.org/building/build.html&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://webkit.org/building/tools.html"&gt;http://webkit.org/building/tools.html&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-3507696848116434170?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=3507696848116434170' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3507696848116434170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3507696848116434170'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/07/building-qtwebkit-on-windows.html' title='Building QtWebKit on Windows'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8317358078127110533</id><published>2010-07-04T14:10:00.002+05:30</published><updated>2010-07-04T14:25:30.174+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='SVN'/><title type='text'>Excluding folders while checking out an SVN repository</title><content type='html'>&lt;p&gt;Blogging this entry out of frustration of not finding an easier way to exclude selected folders while ‘&lt;strong&gt;&lt;em&gt;svn checkout&lt;/em&gt;&lt;/strong&gt;’ing a huge svn repository.&lt;/p&gt;  &lt;p&gt;I had to checkout all folders from &lt;a href="http://svn.webkit.org/repository/webkit/trunk/" target="_blank"&gt;webkit trunk repository&lt;/a&gt; except this folder – &lt;strong&gt;&lt;em&gt;LayoutTests&lt;/em&gt;&lt;/strong&gt;, which was not really necessary for my work. I was not interested in downloading it, as it was really huge and could consume lots of time and bandwidth in downloading it.&lt;/p&gt;  &lt;p&gt;Unfortunately ‘&lt;strong&gt;&lt;em&gt;svn:ignore&lt;/em&gt;&lt;/strong&gt;’ couldn’t helped me in achieving this as I was thinking earlier :(. ‘&lt;strong&gt;&lt;em&gt;svn:ignore&lt;/em&gt;&lt;/strong&gt;’ is meant only for ignoring files/folders while committing/adding them to repository, but not for checking out or updating a repository.&lt;/p&gt;  &lt;p&gt;After googling for a while came to know that only way of achieving this is to use &lt;a href="http://subversion.apache.org/docs/release-notes/1.5.html#sparse-checkouts" target="_blank"&gt;Sparse Checkouts&lt;/a&gt; feature which was introduced since SVN v1.5.&lt;/p&gt;  &lt;p&gt;However, solution is not straight forward. we have to checkout with an option of &lt;strong&gt;&lt;em&gt;--depth=immediates&lt;/em&gt;&lt;/strong&gt; which would checkout all files and folders (excluding everything from sub-folders). Then ‘&lt;strong&gt;&lt;em&gt;svn up&lt;/em&gt;&lt;/strong&gt;’ individual folder which we are interested in.&lt;/p&gt;  &lt;p&gt;I was really not satisfied by this solution. This doesn’t help much in addressing the problem if we do have large number of folders and are in different levels in folder hierarchy.&lt;/p&gt;  &lt;p&gt;Can this be a new feature for svn toolset? or do any one have a better approach for this problem? Let me know.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8317358078127110533?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8317358078127110533' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8317358078127110533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8317358078127110533'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/07/excluding-folders-while-checking-out.html' title='Excluding folders while checking out an SVN repository'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-5693702927896256620</id><published>2010-01-17T11:15:00.002+05:30</published><updated>2010-01-17T12:08:21.733+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Qt'/><category scheme='http://www.blogger.com/atom/ns#' term='Ubuntu'/><title type='text'>Swap space on Ubuntu</title><content type='html'>&lt;p&gt;Had to compile Qt on Ubuntu virtual machine running on Win XP. Compilation used to fail repeatedly for QtGui component with the following error:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;collect2: ld terminated with signal 9 [Killed]&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;With not much error information, I was clueless on what was going wrong!&lt;/p&gt;  &lt;p&gt;Google’ing this error resulted me to learn that &lt;a href="https://help.ubuntu.com/community/SwapFaq"&gt;swap space&lt;/a&gt; reserved was too less (or not at all reserved?) which was required for Qt compilation.&lt;/p&gt;  &lt;p&gt;Then tried using the swapon utility command to check how much swap space is already reserved:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;sudo swapon –s&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Found that nothing was listed at all!&lt;/p&gt;  &lt;p&gt;Executed the following commands to create a swap space of 512MB.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512     &lt;br /&gt;sudo mkswap /mnt/512Mb.swap       &lt;br /&gt;sudo swapon /mnt/512Mb.swap&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This reserved 512MB of swap space, which solved my Qt compilation issues.&lt;/p&gt;  &lt;p&gt;reference : &lt;a title="https://help.ubuntu.com/community/SwapFaq" href="https://help.ubuntu.com/community/SwapFaq"&gt;https://help.ubuntu.com/community/SwapFaq&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-5693702927896256620?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=5693702927896256620' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/5693702927896256620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/5693702927896256620'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2010/01/swap-space-on-ubuntu.html' title='Swap space on Ubuntu'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-7299509868832337342</id><published>2009-10-17T11:35:00.007+05:30</published><updated>2009-10-24T16:02:46.625+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Nokia'/><category scheme='http://www.blogger.com/atom/ns#' term='WRT'/><category scheme='http://www.blogger.com/atom/ns#' term='WebRuntime'/><title type='text'>Developing Applications with Nokia WRT - VTU EduSat ppt</title><content type='html'>Check out this SlideShare Presentation on &lt;span style="font-weight: bold;"&gt;Developing Applications with Nokia Web Runtime&lt;/span&gt;.&lt;br /&gt;This was broadcasted live to all VTU colleges in Karnataka on 14th Sept 2009 as part of VTU's &lt;a href="http://elearning.vtu.ac.in/edusat_bde.htm"&gt;EDUSAT programme&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;My self and &lt;a href="http://anatomistudios.blogspot.com/"&gt;Raghava&lt;/a&gt; had an opportunity to represent &lt;a href="http://www.forum.nokia.com/Technology_Topics/Web_Technologies/Web_Runtime/"&gt;Nokia's Web Runtime&lt;/a&gt;.&lt;br /&gt;We tried to present the latest developments in Nokia's WebRuntime.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;object width="400" height="300"&gt; &lt;param name="flashvars" value="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2F43646951%40N04%2Fsets%2F72157622601952056%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2F43646951%40N04%2Fsets%2F72157622601952056%2F&amp;set_id=72157622601952056&amp;jump_to="&gt;&lt;/param&gt; &lt;param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"&gt;&lt;/param&gt; &lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&amp;lang=en-us&amp;page_show_url=%2Fphotos%2F43646951%40N04%2Fsets%2F72157622601952056%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2F43646951%40N04%2Fsets%2F72157622601952056%2F&amp;set_id=72157622601952056&amp;jump_to=" width="400" height="300"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-7299509868832337342?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=7299509868832337342' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7299509868832337342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7299509868832337342'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/10/developing-applications-with-nokia-wrt.html' title='Developing Applications with Nokia WRT - VTU EduSat ppt'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8918347251803698706</id><published>2009-09-06T22:04:00.002+05:30</published><updated>2009-10-24T16:03:57.025+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='DLL'/><title type='text'>Dependency Walker for Windows binaries</title><content type='html'>&lt;p&gt;I find &lt;a href="http://www.dependencywalker.com/"&gt;Dependency Walker&lt;/a&gt; a very useful utility. This helps us to scan any of windows binaries (exe, dll ...). &lt;/p&gt;  &lt;p&gt;It can dissect almost any type of windows binary file, to show up all possible details hidden within.&lt;/p&gt;  &lt;p&gt;Listing few of the details this utility can provide,&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Basic binary properties Ex: physical path, version info, etc.&lt;/li&gt;    &lt;li&gt;Exported functions with their signatures and ordinal numbers.&lt;/li&gt;    &lt;li&gt;Recursive list of dependent libraries and their details.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;It didn’t took much time for me to discover the power of this tiny tool which is distributed as apart of MS Visual Studio Tools. This can also be downloaded for free at &lt;a title="http://www.dependencywalker.com/" href="http://www.dependencywalker.com/"&gt;http://www.dependencywalker.com/&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Below is one of such situation, where this tool helped me to rapidly identify and debug the problem.&lt;/p&gt;  &lt;p&gt;I was building Qt for Win with ‘-openssl-linked’ option and this required me to download the openSSL libraries separately. I had downloaded and copied ‘libeay32.dll’ under Qt’s bin folder. &lt;/p&gt;  &lt;p&gt;Even though Qt compiled without any problems, I had issues with launching few of the processes which had dependency over libeay32.dll. For some reasons, loader started complaining about missing ordinal in libeay32.dll.&lt;/p&gt;  &lt;p&gt;Dependency walker came into rescue. I simply loaded the failing process into DependencyWalker and it listed all dependent DLLs with respective details. I could just walk to the libeay32.dll and examine its version. &lt;/p&gt;  &lt;p&gt;There you go! It was loading an older version of DLL which had been installed as part of Wireless monitor app. Since PATH variable had the wireless app’s path occurring before Qt’s bin path, it was always picking the older DLL from wrong location which caused the issue.&lt;/p&gt;  &lt;p&gt;It hardly took me few minutes to identify and fix the issue.&lt;/p&gt;  &lt;p&gt;Hope this is useful :)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8918347251803698706?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8918347251803698706' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8918347251803698706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8918347251803698706'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/09/dependency-walker-for-windows-binaries.html' title='Dependency Walker for Windows binaries'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-1107618572972295262</id><published>2009-08-13T08:50:00.002+05:30</published><updated>2009-10-24T16:04:43.121+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web'/><category scheme='http://www.blogger.com/atom/ns#' term='Video'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML5'/><title type='text'>HTML5 video</title><content type='html'>&lt;p&gt;Just wanted to embed a video using HTML5 video feature.&amp;#160; The source looks very simple! &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;video controls=&amp;quot;controls&amp;quot; src=&amp;quot;&lt;a href="http://tinyvid.tv/file/3ifyc1xrvwkjr.ogg&amp;quot;"&gt;http://tinyvid.tv/file/3ifyc1xrvwkjr.ogg&amp;quot;&lt;/a&gt; tabindex=&amp;quot;0&amp;quot;&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;p&amp;gt;       &lt;br /&gt;&amp;#160;&amp;#160; Sorry, your browser doesn't support the &amp;lt;video&amp;gt; element. You'll need a browser that can playback Ogg media using HTML5 video and audio tags.       &lt;br /&gt;&amp;#160;&amp;#160; &amp;lt;/p&amp;gt;       &lt;br /&gt;&amp;lt;/video&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This tries to embed one of my favorite music video – &lt;em&gt;In the Shadows&lt;/em&gt; by &lt;em&gt;The Rasmus&lt;/em&gt; :) &lt;/p&gt; &lt;video tabindex="0" controls="controls" src="http://tinyvid.tv/file/3ifyc1xrvwkjr.ogg"&gt;  &lt;p&gt;Sorry, your browser doesn't support the &lt;video&gt;element. You'll need a browser that can playback Ogg media using &lt;video&gt;and &lt;audio&gt;. &lt;/p&gt; &lt;/video&gt;  &lt;p&gt;Please use the latest versions of Chrome or Firefox to experience the embedded video. The latest versions of Chrome and Firefox are already supporting the HTML5 video and audio features. &lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Reference : &lt;a href="http://dev.w3.org/html5/spec/Overview.html#video"&gt;HTML5 spec&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-1107618572972295262?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=1107618572972295262' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1107618572972295262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1107618572972295262'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/08/html5-video.html' title='HTML5 video'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-133113956213998657</id><published>2009-07-22T20:34:00.002+05:30</published><updated>2009-10-24T16:06:13.453+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ordinals'/><category scheme='http://www.blogger.com/atom/ns#' term='Symbian'/><category scheme='http://www.blogger.com/atom/ns#' term='DLL'/><title type='text'>Resolving the exported symbols from a Symbian DLL</title><content type='html'>&lt;p&gt;Symbian OS optimizes DLL program code to save ROM and RAM space, by offering only &amp;quot;lookup by ordinal&amp;quot; and not &amp;quot;lookup by name&amp;quot;. &lt;/p&gt;  &lt;p&gt;Symbian OS does not offer “lookup by name” because this adds an overhead to the size of the DLL (storing the names of all the functions exported from the library is wasteful of space). Instead, Symbian OS only uses link by ordinal, which has significant implications for binary compatibility.&lt;/p&gt;  &lt;p&gt;If we are loading a DLL dynamically and need to resolve a exported function address, we need to use the following RLibrary API, which takes an integer parameter representing the ordinal number of the exported function.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;TLibraryFunction RLibrary::Lookup(TInt anOrdinal)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Luckily, as part of POSIX for Symbian (P.I.P.S), widely known as Open-C library, we can achieve “lookup by name” with a Symbian DLL.&lt;/p&gt;  &lt;p&gt;This is possible only if the library is built as STDDLL.&lt;/p&gt;  &lt;p&gt;This allows us to have the POSIX like behavior for resolving the exported DLL symbols even on Symbian. Following POSIX like APIs can be used on Symbian provided the DLL is built as STDDLL.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;void *dlopen(const char *filename, int flag);     &lt;br /&gt;void *dlsym(void *handle, const char *symbol);      &lt;br /&gt;void dlclose(void *handle);&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;An example with source using the PIPS libraries is &lt;a href="http://developer.symbian.com/main/documentation/sdl/symbian94/sdk/doc_source/ToolsAndUtilities94/Build-ref/Mmp-ref/targettype.html"&gt;here&lt;/a&gt;. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-133113956213998657?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=133113956213998657' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/133113956213998657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/133113956213998657'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/07/resolving-exported-symbols-from-symbian.html' title='Resolving the exported symbols from a Symbian DLL'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4489021268543256484</id><published>2009-05-31T23:58:00.003+05:30</published><updated>2009-10-24T16:12:18.128+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Digest Authentication'/><category scheme='http://www.blogger.com/atom/ns#' term='WebServer'/><category scheme='http://www.blogger.com/atom/ns#' term='Apache'/><title type='text'>Digest authentication with Apache</title><content type='html'>&lt;p&gt;This article is in continuation with &lt;a href="http://prashanth-cpp.blogspot.com/2009/05/setting-up-http-basic-authentication.html"&gt;previous&lt;/a&gt; and talks about setting up digest authentication with Apache.&lt;/p&gt;  &lt;p&gt;There are few changes compared to the steps for Basic authentication. &lt;/p&gt;  &lt;p&gt;1. Generating the password file for digest auth.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;htdigest -c digest.txt secret prash&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;digest.txt&lt;/strong&gt; is the password file, &lt;strong&gt;secret&lt;/strong&gt; - the realm and &lt;strong&gt;prash&lt;/strong&gt; is the username.&lt;/p&gt;  &lt;p&gt;2. Create htaccess.acl under c:\wamp\www\digest-auth\ with following data&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;AuthUserFile C:\wamp\bin\apache\Apache2.2.11\bin\digest.txt      &lt;br /&gt;AuthName &amp;quot;Protected by Digest auth&amp;quot;       &lt;br /&gt;AuthType Digest       &lt;br /&gt;AuthDigestProvider file &lt;/p&gt;    &lt;p&gt;&amp;lt;Limit GET POST&amp;gt;      &lt;br /&gt;require valid-user       &lt;br /&gt;&amp;lt;/Limit&amp;gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;‘AuthDigestProvider file’ is an additional property that needs to be mentioned for proper working of digest authentication.&lt;/p&gt;  &lt;p&gt;3. And, last but not the least. Enable auth_digest_module by un-commenting the following line if its already commented in httpd.conf.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;LoadModule auth_digest_module modules/mod_auth_digest.so&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Reference : &lt;a title="http://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html" href="http://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html"&gt;http://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4489021268543256484?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4489021268543256484' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4489021268543256484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4489021268543256484'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/05/digest-authentication-with-apache.html' title='Digest authentication with Apache'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-7944002644306223515</id><published>2009-05-31T22:47:00.003+05:30</published><updated>2009-10-24T16:12:44.716+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='WebServer'/><category scheme='http://www.blogger.com/atom/ns#' term='Basic Authentication'/><category scheme='http://www.blogger.com/atom/ns#' term='Apache'/><title type='text'>Setting up HTTP Basic authentication with Apache</title><content type='html'>&lt;p&gt;Last week, I had a chance to setup our test Apache server for Basic and Digest authentication. The setup was required to verify few of the HTTP authentication related test cases.&lt;/p&gt;  &lt;p&gt;I’m blogging it here so that I’ll not forget, if I need it again :) &lt;/p&gt;  &lt;p&gt;I had &lt;a href="http://www.wampserver.com/"&gt;WAMP Server&lt;/a&gt; v2.0&amp;#160; which included Apache v2.2.11 web server. &lt;/p&gt;  &lt;p&gt;Setting up Basic authentication was straight forward.&lt;/p&gt;  &lt;p&gt;1. Update &lt;strong&gt;http.conf&lt;/strong&gt; by adding : &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;AccessFileName htaccess.acl .htaccess &lt;/p&gt; &lt;/blockquote&gt; &lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;p&gt;An htaccess file can be used to modify the Apache configuration on a per-directory basis.&lt;/p&gt;  &lt;p&gt;On some operating systems ‘htaccess.acl’ is not required. Ex, on Linux, you can just mention it as .htaccess. This is because, on Linux you can create a file with name .htaccess.&lt;/p&gt;  &lt;p&gt;2. Add “Directory” tag into &lt;strong&gt;http.conf&lt;/strong&gt; as shown below :&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;lt;Directory &amp;quot;c:/wamp/www/basic-auth/&amp;quot;&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Options None       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; AllowOverride all       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Order Deny,Allow       &lt;br /&gt;&amp;lt;/Directory&amp;gt;&lt;/p&gt; &lt;/blockquote&gt; &lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;p&gt;&lt;strong&gt;c:/wamp/www/basic-auth/&lt;/strong&gt; is the folder which needs to be secured by the authentication scheme which we are trying to impose.&lt;/p&gt;  &lt;p&gt;3. Next step is to create password file. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;cd C:\wamp\bin\apache\Apache2.2.11\bin      &lt;br /&gt;htpasswd -c pwd.txt prash&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This prompts for the password for the username – ‘prash’. After supplying the password we will be ready with the password file – ‘pwd.txt’ under ‘C:\wamp\bin\apache\Apache2.2.11\bin’.&lt;/p&gt;  &lt;p&gt;4. Create the htaccess file - ‘htaccess.acl’ file with the following data. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;AuthUserFile C:\wamp\bin\apache\Apache2.2.11\bin\pwd.txt      &lt;br /&gt;AuthName &amp;quot;Protected&amp;quot;       &lt;br /&gt;AuthType Basic &lt;/p&gt;    &lt;p&gt;&amp;lt;Limit GET POST&amp;gt;      &lt;br /&gt;require valid-user       &lt;br /&gt;&amp;lt;/Limit&amp;gt;&lt;/p&gt; &lt;/blockquote&gt; &lt;style type="text/css"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt; font-size: small;&lt;br /&gt; color: black;&lt;br /&gt; font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt; background-color: #ffffff;&lt;br /&gt; /*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt; background-color: #f4f4f4;&lt;br /&gt; width: 100%;&lt;br /&gt; margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;p&gt;This specifies which password file need to be considered for the authentication – ‘C:/wamp/bin/apache/Apache2.2.11/bin/pwd.txt’ also the type of authentication scheme – Basic.&lt;/p&gt;  &lt;p&gt;Place this file under the folder ‘c:/wamp/www/basic-auth/’ along with other live data and restart the server.&lt;/p&gt;  &lt;p&gt;Now, try accessing the folder &lt;a href="http://localhost/basic-auth"&gt;http://localhost/basic-auth&lt;/a&gt;. This should prompt for username and password.&lt;/p&gt;  &lt;p&gt;Reference : &lt;a title="http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html" href="http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html"&gt;http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-7944002644306223515?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=7944002644306223515' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7944002644306223515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7944002644306223515'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/05/setting-up-http-basic-authentication.html' title='Setting up HTTP Basic authentication with Apache'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-154342294419339415</id><published>2009-05-02T11:18:00.003+05:30</published><updated>2009-10-24T16:08:08.365+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='MoFuse'/><category scheme='http://www.blogger.com/atom/ns#' term='Mobile'/><category scheme='http://www.blogger.com/atom/ns#' term='Blog'/><title type='text'>Making my blog 'Mobile Friendly'</title><content type='html'>Being part of mobile software industry and that too working for &lt;a href="http://www.s60.com/life/thisiss60/s60indetail/technologiesandfeatures/webrowser"&gt;&lt;i&gt;S60 Browser&lt;/i&gt;&lt;/a&gt; research team, I desperately wanted to make my blog mobile friendly. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Unfortunately &lt;a href="http://www.blogger.com/"&gt;Blogger&lt;/a&gt;, where this blog is hosted lacks this service. This would be a very nice and really useful feature. &lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Wordpress&lt;/span&gt;&lt;/b&gt; seems to offer this already - &lt;a href="http://wordpressmobile.mobi/"&gt;http://wordpressmobile.mobi/&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;After I did some googling I came across &lt;a href="http://www.blogger.com/www.mofuse.com/"&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;MoFuse&lt;/span&gt;&lt;/a&gt;. &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;Mofuse&lt;/span&gt; provides feeds based solution to convert your blogs to mobile readable version.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Setting up a mobilized version with &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;MoFuse&lt;/span&gt; was pretty straight forward, I just registered for a new mobilized blog URL - &lt;a href="http://prashtech.mofuse.mobi/"&gt;http://prashtech.mofuse.mobi&lt;/a&gt; which internally points to my blogs' &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;RSS&lt;/span&gt; feeds.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That's it. If any of you visiting my blog from your mobile, try the mobilized version of my Blog!&lt;/div&gt;&lt;div&gt;&lt;a href="http://prashtech.mofuse.mobi/"&gt; http://prashtech.mofuse.mobi&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-154342294419339415?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=154342294419339415' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/154342294419339415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/154342294419339415'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/05/making-my-blog-mobile-friendly.html' title='Making my blog &apos;Mobile Friendly&apos;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-2850825455839536434</id><published>2009-01-11T21:36:00.004+05:30</published><updated>2010-01-17T11:20:02.280+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='BackwardCompatibility'/><category scheme='http://www.blogger.com/atom/ns#' term='DLL'/><category scheme='http://www.blogger.com/atom/ns#' term='PIMPL'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Backward Compatibility with DLLs – Part 2 (Private Implementation)</title><content type='html'>&lt;p&gt;A very Happy New Year to all of the readers!&lt;/p&gt; &lt;p&gt;This article is in continuation with the previous one, about preserving DLL  exported APIs’ backward compatibility.&lt;/p&gt; &lt;p&gt;The last article described a technique of achieving this by privatizing the  API’s constructor. This has many disadvantages of its own, as the c’tor is  private, ex: Object can not be instantiated on stack.&lt;/p&gt; &lt;p&gt;An alternative technique is to have a &lt;strong&gt;“Private  Implementation”&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;If you have a class, which you intend to export, separate out all the  internal implementation including the data members and the functions which you  think can be hidden. The exported class will only have the functions exported  along with a private member pointer to the new internal class. &lt;/p&gt; &lt;p&gt;As an example, consider the following class,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;#define DLL_EXPORT __declspec(dllexport)&lt;br /&gt;class DLL_EXPORT ExampleExport&lt;br /&gt;{&lt;br /&gt;public: // c'tors and d'tors&lt;br /&gt;    ExampleExport();&lt;br /&gt;     ~ExampleExport(); &lt;/p&gt; &lt;p&gt;public: // functions&lt;br /&gt;    void function1();&lt;br /&gt;    int function2(); &lt;/p&gt; &lt;p&gt;private: // private data members&lt;br /&gt;    int m_member1;&lt;br /&gt;    int  m_member2;&lt;br /&gt;};&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;We have 2 integer member variables. Adding or removing the member variables  later, will always cause a binary compatibility break as described in the  previous article.&lt;/p&gt; &lt;p&gt;Let’s try to separate out the internal implementation. We will move all the  private data members to a different class – ExampleExportPrivate.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;class ExampleExportPrivate&lt;br /&gt;{&lt;br /&gt;public: // c'tors and d'tors&lt;br /&gt;     ExampleExportPrivate();&lt;br /&gt;    ~ExampleExportPrivate(); &lt;/p&gt; &lt;p&gt;public: // data members&lt;br /&gt;    int m_member1;&lt;br /&gt;    int m_member2;&lt;br /&gt;};&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;We will redefine ExampleExport to use ExampleExportPrivate.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;#define DLL_EXPORT __declspec(dllexport) &lt;/p&gt; &lt;p&gt;class ExampleExportPrivate; // &lt;&lt;-- forward declaration of the private  implementation which is defined in cpp file&lt;/p&gt; &lt;p&gt;&lt;br /&gt;class DLL_EXPORT ExampleExport&lt;br /&gt;{&lt;br /&gt;public: // c'tors and d'tors&lt;br /&gt;    ExampleExport();&lt;br /&gt;    ~ExampleExport(); &lt;/p&gt; &lt;p&gt;public: // functions&lt;br /&gt;    void function1();&lt;br /&gt;    int function2(); &lt;/p&gt; &lt;p&gt;private:&lt;br /&gt;    ExampleExportPrivate *m_private; // &lt;—Pointer to private  implementation. };&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;As a first step, forward declare the private implementation class –  ExampleExportPrivate. The actual definition of this private implementation class  can be placed as part of the cpp file. So, we are not exposing this class  outside, even in the header files exported. Next step is to have a private  pointer member variable which points to ExampleExportPrivate. Any references to  the data will be redirected to the internal private implementation.&lt;/p&gt; &lt;p&gt;This technique will help us to not change the size of the exported class. If  we need to add or delete a new member variable, ExampleExportPrivate will be the  class which will have those changes, but not ExampleExport.&lt;/p&gt; &lt;p&gt;This technique is usually called as “PImpl” (Private Implementation). Here is  an interesting article &lt;a href="http://www.gotw.ca/publications/mill04.htm"&gt;http://www.gotw.ca/publications/mill04.htm&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-2850825455839536434?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=2850825455839536434' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2850825455839536434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2850825455839536434'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2009/01/very-happy-new-year-to-all-of-readers.html' title='Backward Compatibility with DLLs – Part 2 (Private Implementation)'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-7776143624877181705</id><published>2008-12-01T00:11:00.003+05:30</published><updated>2010-01-17T11:20:32.596+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='BackwardCompatibility'/><category scheme='http://www.blogger.com/atom/ns#' term='DLL'/><category scheme='http://www.blogger.com/atom/ns#' term='PIMPL'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Backward Compatibility with DLLs</title><content type='html'>&lt;p&gt;This and the following articles, I personally feel very interesting.&lt;/p&gt;  &lt;p&gt;It’s related to the “&lt;em&gt;backward compatibility&lt;/em&gt;” of the DLLs. &lt;/p&gt;  &lt;p&gt;If you are distributing your DLLs to people or 3rd party, whom you expect to use them, you should be very careful about the interface you expose out of the DLLs. &lt;/p&gt;  &lt;p&gt;Consider you are distributing a DLL, which has an exported class of some size and few public functions. If you update the same DLL in future and redistribute it, you cannot always expect the users to re-link their application with your new DLL. In such cases, users of the DLL expect the same interface what you had provided in the earlier release. If by any way there is a change in the interface, it results in failure of backward compatibility.&lt;/p&gt;  &lt;p&gt;Let’s take an example to explain this situation. The following is a class which you are exporting as part of your DLL,&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;#define DLL_EXPORT __declspec(dllexport) &lt;/p&gt;    &lt;p&gt;class DLL_EXPORT ExampleExport     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ExampleExport();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ~ExampleExport(); &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; void function1();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int function2(); &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private: &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int m_member1;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int m_member2;      &lt;br /&gt;};&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In a future release you updated this class to have an additional member variable,&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;class DLL_EXPORT ExampleExport     &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ExampleExport();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ~ExampleExport(); &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; void function1();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int function2(); &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private: &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int m_member1;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int m_member2;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int m_member3; // &amp;lt;&amp;lt;---- a new member variable added      &lt;br /&gt;};&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You can observer that the class size has been changed. Earlier it was 8 bytes (assuming int as 4 bytes) and it’s changed to 12 by adding an additional integer member variable.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Consequence&lt;/strong&gt;: For an end user application, which is not re-linked with the updated DLL, the size of the class is still 8 bytes. Since the application was compiled and linked with the first version of DLL, the size is still the same even after they started using the new DLL. The application may have unpredicted behavior.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Resolution&lt;/strong&gt;: This problem needs to be addressed before we release the first version of the DLL. Of course we cannot restrict the size of the class to not to change in future. We may need to update it by adding or removing new member variables. One solution is to force the end user application to not to construct the object by itself.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Make constructor private. &lt;/li&gt;    &lt;li&gt;Export a new static member function which creates an object by calling private constructor&lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;class DLL_EXPORT ExampleExport     &lt;br /&gt;{      &lt;br /&gt;public:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ~ExampleExport(); &lt;/p&gt;    &lt;p&gt;public:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; static ExampleExport* Instance();&lt;/p&gt;    &lt;p&gt;public:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; void function1();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int function2(); &lt;/p&gt;    &lt;p&gt;private:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; ExampleExport(); // &amp;lt;&amp;lt;---- private constructor &lt;/p&gt;    &lt;p&gt;private:      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int m_member1;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int m_member2;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int m_member3; // &amp;lt;&amp;lt;---- a new member variable added      &lt;br /&gt;};&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This forces the client application to use ExampleExport::Instance() function always to construct an object and since the definition of Instance() is part of the DLL, 12 bytes will be allocated with the new DLL.&lt;/p&gt;  &lt;p&gt;Let’s have a look at another solution for the same problem, in the next article.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-7776143624877181705?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=7776143624877181705' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7776143624877181705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7776143624877181705'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2008/12/backward-compatibility-with-dlls.html' title='Backward Compatibility with DLLs'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-1064307441341016406</id><published>2008-06-01T22:34:00.002+05:30</published><updated>2009-10-24T16:11:22.421+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Forward Declarations</title><content type='html'>&lt;p&gt;We can use forward declaration to speedup the compilation and to reduce the interdependencies between different modules.  &lt;p&gt;Consider following CServer and CClient classes, declared in Server.h and Client.h header files respectively. &lt;p&gt;&lt;strong&gt;Server.h &lt;/strong&gt; &lt;blockquote&gt; &lt;p&gt;#include "Client.h"  &lt;p&gt;class CServer&amp;nbsp; &lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CServer();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~CServer();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SendMsg(CClient &amp;amp;clnt);  &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CClient *m_ptrClient;&lt;br&gt;};&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In&amp;nbsp;this case it will always be more efficient to omit the inclusion of the header file Client.h, instead we can use forward declaration as shown below, &lt;blockquote&gt; &lt;p&gt;class CClient;  &lt;p&gt;class CServer&amp;nbsp; &lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CServer();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~CServer();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SendMsg(CClient &amp;amp;clnt);  &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CClient *m_ptrClient;&lt;br&gt;};&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is sufficient in this case because of the reason that C++ compiler is optimized enough and it doesn't need to know about the size and interfaces of the class CClient within the declaration of the CServer class.  &lt;p&gt;However we have to include the Client.h header in Server.cpp where the actual definition of the member functions exist.  &lt;p&gt;Below are some use cases which indicates the usage of forward declarations,  &lt;blockquote&gt; &lt;p&gt;class CClient;  &lt;p&gt;class CServer&amp;nbsp; &lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CServer();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~CServer();  &lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SendMsg(CClient clnt);&amp;nbsp; // non-ref/pointer parameter&lt;/strong&gt; &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CClient *m_ptrClient;&lt;br&gt;}; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Usage of forward declaration is valid even though we have non-reference or non-pointer parameter in the member function.  &lt;p&gt;&amp;nbsp; &lt;p&gt;Below is a case where we cannot use forward declaration, &lt;blockquote&gt; &lt;p&gt;class CClient;  &lt;p&gt;class CServer&amp;nbsp; &lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CServer();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~CServer();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SendMsg(CClient clnt) { clnt.updateMsg(); }&amp;nbsp;// inline definition &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CClient *m_ptrClient;&lt;br&gt;}; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Cannot use forward declaration here because SendMsg has&amp;nbsp;it's inline definition which is actually using CClient::updateMsg(). In this case we need to include the header Client.h within Server.h  &lt;p&gt;&amp;nbsp; &lt;p&gt;One more case where we can not use forward declaration, &lt;blockquote&gt; &lt;p&gt;class CClient;  &lt;p&gt;class CServer&amp;nbsp; &lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CServer();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual ~CServer();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void SendMsg(CClient clnt);  &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CClient m_client;&lt;br&gt;}; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Since the member variable m_client within CServer is of type CClient, compiler need to know about the CClient. We cannot use the forward declaration here.  &lt;p&gt;Rule of Thumb : "&lt;strong&gt;If the compiler doesn't need it, you won't have to do it.&lt;/strong&gt;" C++ is well optimized.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-1064307441341016406?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=1064307441341016406' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1064307441341016406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1064307441341016406'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2008/06/forward-declarations.html' title='Forward Declarations'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-3626637283321612998</id><published>2008-01-09T00:48:00.003+05:30</published><updated>2009-10-24T16:17:24.943+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='RTTI'/><category scheme='http://www.blogger.com/atom/ns#' term='dynamic_cast'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>dynamic_casting with pointers and references</title><content type='html'>&lt;p&gt;First of all a very warm happy new year to all the readers. Its been a while since&amp;nbsp;the last post.&lt;/p&gt; &lt;p&gt;Today I intend to write about dynamic_cast again. There's already an article about &lt;a href="http://prashanth-cpp.blogspot.com/2007/06/dynamiccast.html"&gt;dynamic_cast&lt;/a&gt;. The reason why I'm writing about this is to show with some samples how we can use dynamic cast with pointers and also with references. &lt;/p&gt; &lt;p&gt;Yes, RTTI can be implemented both with pointers and references.&lt;/p&gt; &lt;p&gt;Below sample shows how to use dynamic_cast with pointers. I have considered the same example classes which were there in the &lt;a href="http://prashanth-cpp.blogspot.com/2007/06/dynamiccast.html"&gt;dynamic_cast&lt;/a&gt;&amp;nbsp;article .&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void ProcessButtonEvent(CControlIface *pControl)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Here we need make sure safe down-cast happens&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CButtonControl *pButton = dynamic_cast &amp;lt;CButtonControl *&amp;gt; (pControl); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // casting works fine here since we had passed pControl1  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(pButton != NULL)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pButton-&amp;gt;OnClick();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We can now safely call OnClick() of CButtonControl&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; "dynamic_cast failed. pControl is not pointing to instance of CButtonControl"&amp;lt;&amp;lt;endl; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;We need to note here that whenever dynamic cast fails with pointers it returns NULL. This is the reason why we are checking for &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;pButton!=NULL&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;br&gt;Lets try dynamic casting with references,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void ProcessButtonEvent(CControlIface &amp;amp;Control)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Here we need make sure safe down-cast happens&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CButtonControl &amp;amp;Button = dynamic_cast &amp;lt;CButtonControl &amp;amp;&amp;gt; (Control);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Button.OnClick();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch(bad_cast)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout &amp;lt;&amp;lt; "Caught: bad_cast exception. This control is not a button"&amp;lt;&amp;lt;endl; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In case of references if dynamic_cast fails, it throws bad_cast exception. This is the reason why we are catching the exception in the above code sample. &lt;p&gt;Please note that some old compilers may not support dynamic_cast. In that case its high time for you to upgrade your C++ compiler!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-3626637283321612998?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=3626637283321612998' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3626637283321612998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3626637283321612998'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2008/01/dynamiccasting-with-pointers-and.html' title='dynamic_casting with pointers and references'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4396672841458161225</id><published>2007-09-04T21:41:00.002+05:30</published><updated>2009-10-24T16:13:14.874+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='operator new'/><category scheme='http://www.blogger.com/atom/ns#' term='Overloading'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Global vs Member overloaded operator new</title><content type='html'>&lt;p&gt;In an earlier post we saw how to &lt;a href="http://prashanth-cpp.blogspot.com/2007/08/overloading.html"&gt;overload operator new&lt;/a&gt;, which will allow us to have customized memory allocation for an object on heap.&lt;/p&gt; &lt;p&gt;Its possible to place this overloaded operator new function either globally or as member function within a class.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;// Global overloaded operator new&lt;br&gt;void *operator new(size_t size)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return malloc(size);&lt;br&gt;}  &lt;p&gt;&amp;nbsp;  &lt;p&gt;// Class CTest&lt;br&gt;class CTest&lt;br&gt;{&lt;br&gt;public:  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Member overloaded operator new &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void *operator new(size_t size)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return malloc(size);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;};&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&amp;nbsp;  &lt;p&gt;Is there any behavioral difference between these two versions of operator new?&lt;/p&gt; &lt;p&gt;Yes, there is.&lt;/p&gt; &lt;p&gt;If we have overloaded new as a member function within a class, it will always have high precedence over the globally defined version.&lt;/p&gt; &lt;p&gt;If we have a globally defined operator new function, the same will be used for all classes which doesn't have overloaded operator new defined within. &lt;/p&gt; &lt;p&gt;If both exist, the member version will be preferred over the global version.&lt;/p&gt; &lt;p&gt;Is there any advantage of this feature?&lt;/p&gt; &lt;p&gt;Yes.&lt;/p&gt; &lt;p&gt;Global version of overloaded operator new will be very much useful when we need to have a common strategy for memory allocation for all the classes in the module.&lt;/p&gt; &lt;p&gt;If we are in a situation where we need to have a specific way for allocation for a particular class which is different from others then we can overload operator new for the class with desired allocation method. A good example would be to allocate and initialize the allocated memory with zeros.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4396672841458161225?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4396672841458161225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4396672841458161225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4396672841458161225'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/09/global-vs-member-overloaded-operator.html' title='Global vs Member overloaded operator new'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-3177723638989520373</id><published>2007-08-15T12:41:00.002+05:30</published><updated>2009-10-24T16:13:36.464+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='constructors'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Zombie</title><content type='html'>&lt;p&gt;This article talks about handling a &lt;em&gt;failing constructor&lt;/em&gt;.  &lt;p&gt;What does it mean when I say &lt;em&gt;Failing Constructor&lt;/em&gt;? &lt;p&gt;Consider&amp;nbsp;a situation where we have written a constructor for a class and for some reasons it fails before fully executing&amp;nbsp;the constructor. Constructor wont return any value, so it wont be possible for us to tell whether the constructor is fully executed or not.  &lt;p&gt;What's the state of the object in this case?  &lt;p&gt;Its a &lt;em&gt;zombie&lt;/em&gt; object, because of the reason that the construction of the object has not happened in the expected way. &lt;p&gt;What's the problem with &lt;em&gt;zombie&lt;/em&gt; objects?&lt;/p&gt; &lt;p&gt;Constructor has not executed completely, it has&amp;nbsp;ended unexpectedly.&amp;nbsp;This means the object has not been constructed. Hence, Destructor for the same object wont be executed. We will encounter problem, If we have done any dynamic allocations or opened any resource handles in the constructor before&amp;nbsp;it fails, because the memory allocated wont be freed since the code for freeing up the memory or closing the resource handles usually sits in&amp;nbsp;the destructor.&lt;/p&gt; &lt;p&gt;Code below explains this&amp;nbsp;situation,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;class CTest&lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Constructor&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTest();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Destructor&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~CTest();  &lt;p&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Member pointer variables&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *m_ptr1;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *m_ptr2;&lt;br&gt;};  &lt;p&gt;// Constructor definition&lt;br&gt;CTest::CTest()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Init member pointers&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr1 = m_ptr2 = NULL;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr1 = new char[100]; // Assume this succeeds  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr2 = new char[100]; // Assume this fails here!  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Other processing &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;} &lt;/p&gt; &lt;p&gt;// Destructor definition&lt;br&gt;CTest::~CTest()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete [] m_ptr1;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete [] m_ptr2;&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Have a look at the constructor CTest::CTest(), assume the first dynamic allocation succeeded for m_ptr1 and m_ptr2 failed for some reasons. Since the object is not constructed fully destructor wont be called and hence the heap allocations are not freed.&lt;/p&gt; &lt;p&gt;How do we overcome this problem?&lt;/p&gt; &lt;p&gt;One solution would be to catch the exception, free the allocated memory and then re throw the exception. Following code will show this technic.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;// Constructor definition&lt;br&gt;CTest::CTest()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Init member pointers&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr1 = m_ptr2 = NULL;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // try block&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr1 = new char[100]; // Assume this succeeds  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_ptr2 = new char[100]; // Assume this fails here!  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Other processing &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // catch block&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch(...)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // free the resources&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete [] m_ptr1;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete [] m_ptr2; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // re-throw &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Another solution would be to use &lt;a href="http://prashanth-cpp.blogspot.com/2007/07/smart-pointers.html"&gt;smart pointers&lt;/a&gt;, instead of just the raw pointers. When exception is thrown, the destructors for the local variables will be called as part of stack-unwinding which calls the destructor of the smart pointer which in turn frees the resources.&lt;/p&gt; &lt;p&gt;Enjoy C++!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-3177723638989520373?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=3177723638989520373' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3177723638989520373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3177723638989520373'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/08/zombie.html' title='Zombie'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-2408648766274566501</id><published>2007-08-08T21:56:00.002+05:30</published><updated>2009-10-24T16:14:09.435+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='constructors'/><category scheme='http://www.blogger.com/atom/ns#' term='operator new'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Overloading "new"</title><content type='html'>&lt;p&gt;In one of the previous article&amp;nbsp;about &lt;a href="http://prashanth-cpp.blogspot.com/2007/06/whats-new.html"&gt;&lt;em&gt;operator new&lt;/em&gt;&lt;/a&gt;, we saw that it can always be overloaded. &lt;/p&gt; &lt;p&gt;&lt;em&gt;operator new&lt;/em&gt; can be overloaded to define its own way of allocating memory for an object. User should be able to control the way how it allocates the memory for the object.&lt;/p&gt; &lt;p&gt;The&amp;nbsp;global &lt;em&gt;new operator&lt;/em&gt; is the one which invokes a call to appropriate version of &lt;em&gt;operator new&lt;/em&gt; if its overloaded and then it will call the constructor to complete the object instantiation process.&lt;/p&gt; &lt;p&gt;Below is the pseudo code of what &lt;em&gt;new operator &lt;/em&gt;does &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;new()&lt;br&gt;{  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Call correct version of &lt;em&gt;operator new&lt;/em&gt;() based on the parameters passed while initializing the object&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; operator new(sizeof(CMyClass));  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Call appropriate version of constructor&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyClass::CMyClass();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;p&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Function &lt;em&gt;operator new&lt;/em&gt; always&amp;nbsp;has&amp;nbsp;&lt;em&gt;size_t&lt;/em&gt; as one of its parameter. The functionality of a default &lt;em&gt;operator new&lt;/em&gt; will be as shown below,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void* operator new(size_t size)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // allocate and return the pointer&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return malloc(size);&amp;nbsp; &lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Where it allocates &lt;em&gt;size&lt;/em&gt; number of bytes and return the pointer which points to the allocated memory.&lt;/p&gt; &lt;p&gt;If user tries to instantiate an object of type CMyClass dynamically,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;CMyClass *pObj = new CMyClass();&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This will call the global &lt;em&gt;new operator() &lt;/em&gt;function which will first call &lt;em&gt;operator new(sizeof(CMyClass))&lt;/em&gt; passing &lt;em&gt;sizeof(CMyClass)&lt;/em&gt; as parameter to allocate required memory, then it will call the constructor &lt;em&gt;CMyClass::CMyClass()&lt;/em&gt; to finish the object instantiation process.&lt;/p&gt; &lt;p&gt;In some cases user may want to allocate memory for an object in a predefined memory area. This can be achieved by overloading &lt;em&gt;operator new()&lt;/em&gt;.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void* operator new(size_t size, void *pMem)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // just return the&amp;nbsp;pre allocated memory pointer&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return pMem;&amp;nbsp; &lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;User can invoke this by doing the following,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;char *buf&amp;nbsp; = new char[500];&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //pre-allocated buffer&lt;br&gt;CMyClass *pObj = new (buf) CMyClass();&amp;nbsp;&amp;nbsp;&amp;nbsp; //placement new&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This will invoke the overloaded version of function &lt;em&gt;operator new()&lt;/em&gt; which takes two parameters, first would be the size of the class and the next would be the pointer to pre-allocated buffer.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;operator new(sizeof(CMyClass), buff);&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;And this overloaded version will just return the pointer to new operator() function which will then call the appropriate constructor.&lt;/p&gt; &lt;p&gt;This technic is&amp;nbsp;popularly known as&amp;nbsp;&lt;em&gt;Placement New&lt;strong&gt;.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;In the same way user should be able to overload &lt;em&gt;operator new&lt;/em&gt; with different parameters.&lt;/p&gt; &lt;p&gt;Cheers!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-2408648766274566501?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=2408648766274566501' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2408648766274566501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2408648766274566501'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/08/overloading.html' title='Overloading &amp;quot;new&amp;quot;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4193963723129796694</id><published>2007-08-03T09:53:00.002+05:30</published><updated>2009-10-24T16:14:26.649+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Overloading'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Overloading const and non-const member functions</title><content type='html'>&lt;p&gt;We all know&amp;nbsp;about&amp;nbsp;the function overloading feature in C++. Where we can have the same name given for a function with different signatures. Different signature here means different types or number of arguments for that function.&lt;/p&gt; &lt;p&gt;How about overloading based on &lt;em&gt;constness&lt;/em&gt; of a member function?&lt;/p&gt; &lt;p&gt;Consider the scenario below,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;class MyArray&lt;br&gt;{&lt;br&gt;private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int m_iInts[100];&amp;nbsp; // Array of integers  &lt;p&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int&amp;amp; operator [](int iIndex);&amp;nbsp; // Overloading subscript operator&lt;br&gt;};  &lt;p&gt;int&amp;amp; MyArray::operator[](int iIndex) // Definition&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_iInts[iIndex];&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;We are trying to create an integer array class, with an overloaded operator function for subscript access of the array. &lt;/p&gt; &lt;p&gt;we should be able to say&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;MyArray objArray;&lt;br&gt;objArray[10] = 100;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This will establish a call to the member function operator[](int), which returns a reference to the requested array member.&amp;nbsp;It will assign a value to that particular array member. &lt;/p&gt; &lt;p&gt;But, consider the situation below,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void PrintArray(const MyArray &amp;amp;obj)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Code for printing the elements&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;obj[10]&amp;lt;&amp;lt;endl;&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Assume that this is a function for printing the array elements. This takes a constant reference to MyArray instance as parameter. &lt;/p&gt; &lt;p&gt;Problem is here!&lt;/p&gt; &lt;p&gt;When we try to print the value by saying obj[10], since the object is of constant type, it will not be able to access the non-const version of operator[](int).&lt;/p&gt; &lt;p&gt;Compiler complains about this saying &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;no operator defined which takes a left-hand operand of type 'const class MyArray'&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In this situation we must declare another version of operator[](int) which will be specifically for const objects.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;const int MyArray::operator[](int index) const&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_iElements[index];&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is a const member function - meaning not supposed to change value of any member variable.&lt;/p&gt; &lt;p&gt;Hence we have 2 versions of member functions with same name and even same argument but different in &lt;em&gt;constness&lt;/em&gt;.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;int&amp;amp; operator [](int iIndex);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// non-const version &lt;br&gt;const int operator[](int index) const;&amp;nbsp;&amp;nbsp;&amp;nbsp; // const version &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;The first version will be used for all non-const objects and the later will be only used for const objects. &lt;p&gt;Happy coding!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4193963723129796694?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4193963723129796694' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4193963723129796694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4193963723129796694'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/08/overloading-const-and-non-const-member.html' title='Overloading const and non-const member functions'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8702391937345637126</id><published>2007-08-01T01:19:00.002+05:30</published><updated>2009-10-24T16:14:44.585+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Accessing non-static member function without object!</title><content type='html'>&lt;p&gt;We know that we can call a static member function with in a class without instantiating that class. But how about a non-static member function? &lt;/p&gt; &lt;p&gt;Its possible too, unless we try to access any of the member variable within that function.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;class CTest&lt;br&gt;{&lt;br&gt;public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void func()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;"I can execute even without an object!"&amp;lt;&amp;lt;endl;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;};  &lt;p&gt;int main()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTest *p = 0; // NULL pointer&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; p-&amp;gt;func();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Calling member function &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br&gt;}&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This compiles and works fine. &lt;/p&gt; &lt;p&gt;But beware! We must not try to access any of the member variables within that because &lt;em&gt;this&lt;/em&gt; pointer will be pointing to NULL.&lt;/p&gt; &lt;p&gt;Remember there was an article about how a &lt;a href="http://prashanth-cpp.blogspot.com/2007/05/resolving-function-address.html"&gt;member function call&lt;/a&gt; is made?&lt;/p&gt; &lt;p&gt;Cheers!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8702391937345637126?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8702391937345637126' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8702391937345637126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8702391937345637126'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/08/accessing-non-static-member-function.html' title='Accessing non-static member function without object!'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-7915764888271087201</id><published>2007-07-30T11:10:00.001+05:30</published><updated>2009-10-24T16:15:09.547+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Bjarne Stroustrup'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>How to pronounce Bjarne Stroustrup?</title><content type='html'>Here is an &lt;a href="http://www.research.att.com/~bs/pronounciation.wav"&gt;audio-link&lt;/a&gt; in which Bjarne himself tells how to pronounce his name.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-7915764888271087201?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=7915764888271087201' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7915764888271087201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7915764888271087201'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/07/how-to-pronounce-bjarne-stroustrup.html' title='How to pronounce Bjarne Stroustrup?'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-6845236547148759654</id><published>2007-07-28T22:24:00.002+05:30</published><updated>2009-10-24T16:15:28.388+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='RTTI'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>RTTI</title><content type='html'>&lt;p&gt;&lt;strong&gt;Run Time Type Information&lt;/strong&gt; (RTTI)&amp;nbsp;is the concept which facilitates us to identify type of a polymorphic object at run time (typeid operator)&amp;nbsp;and to perform type-safe down casting. There is an article already in this blog about type-safe down-casting&amp;nbsp; - &lt;a href="http://prashanth-cpp.blogspot.com/2007/06/dynamiccast.html"&gt;dynamic_cast&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;typeid&lt;/strong&gt; is an operator which can be used to find out the dynamic type of a polymorphic object. It can be used to identify the type of the object referenced by or pointed at run time.&lt;/p&gt; &lt;p&gt;When do we need to use it?&lt;/p&gt; &lt;p&gt;Ideally never. If we design the system properly we shouldn't be using this operator. But in certain cases where we cannot avoid,&amp;nbsp;we may have to use &lt;strong&gt;typeid&lt;/strong&gt; operator.&lt;/p&gt; &lt;p&gt;Let's look at an example.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;class CShape&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;};  &lt;p&gt;class CCircle : public CShape&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;};  &lt;p&gt;class CRectangle : public CShape&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;};  &lt;p&gt;void Draw(CShape *pShape)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(typeid(*pShape) == typeid(CCircle))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;"Circle"&amp;lt;&amp;lt;endl;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if(typeid(*pShape) == typeid(CSquare))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;"Circle"&amp;lt;&amp;lt;endl;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}  &lt;p&gt;int main()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CCircle *circle = new CCircle();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSquare *square = new CSquare();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Draw(circle);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Draw(square);&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This prints "Circle" and "Rectangle".&lt;/p&gt; &lt;p&gt;In function Draw(), typeid is returning the polymorphic type of the object pointed by pShape which is unknown at compilation type.&lt;/p&gt; &lt;p&gt;typeid uses RTTI to find out the class type at run time. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-6845236547148759654?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=6845236547148759654' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6845236547148759654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6845236547148759654'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/07/rtti.html' title='RTTI'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4360494515281350508</id><published>2007-07-14T11:58:00.002+05:30</published><updated>2009-10-24T16:15:56.707+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Smart Pointers'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Don't ever mix Arrays with auto_ptr !</title><content type='html'>&lt;p&gt;This article is in response to one of the comments for my previous article about &lt;a href="http://prashanth-cpp.blogspot.com/2007/07/smart-pointers.html"&gt;auto_ptr&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;auto_ptr&lt;/strong&gt; which is provided by the standard C++ library wont work with arrays. It's best to avoid using auto_ptr for arrays.&lt;/p&gt; &lt;p&gt;What is the problem?&lt;/p&gt; &lt;p&gt;To understand the problem, let's take a loot at C++'s&amp;nbsp;memory management background. We all know that,&amp;nbsp;any "new" statement we use for dynamically creating object should be accompanied with a call to "delete" for deleting that object.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;CMyClass *p = new CMyClass; //Dynamically create an object  &lt;p&gt;// some other processing&lt;br&gt;...  &lt;p&gt;delete p; // delete the object&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Also, if we are allocating an array of objects using &lt;strong&gt;new[], &lt;/strong&gt;that must be freed using &lt;strong&gt;delete[]&lt;/strong&gt; operator, which frees up all the dynamically allocated objects.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;CMyClass *p = new CMyClass[5]; //Dynamically create array of objects  &lt;p&gt;// some other processing&lt;br&gt;...  &lt;p&gt;delete[] p; // delete the objects&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;In case of auto_ptr, the destructor will just do a &lt;strong&gt;delete&lt;/strong&gt; on the embedded pointer member variable. &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;auto_ptr::~auto_ptr()&amp;nbsp;&amp;nbsp;&amp;nbsp; // Destructor&amp;nbsp;&amp;nbsp; &lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete ptr;&amp;nbsp; // free the memory&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;There's no way for auto_ptr to intelligently do &lt;strong&gt;delete&lt;/strong&gt; or &lt;strong&gt;delete[]&lt;/strong&gt;&amp;nbsp;based on&amp;nbsp;the scalar or vector&amp;nbsp;dynamic objects pointed by the member pointer.&lt;/p&gt; &lt;p&gt;If we do&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;auto_ptr&amp;lt;int&amp;gt; obj(new int[10]);&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;When &lt;strong&gt;obj&lt;/strong&gt; goes out of scope, the destructor will be called and only delete will be done on the pointer. Which ideally had to be delete []. This causes leak and may cause undefined behavior.&lt;/p&gt; &lt;p&gt;Its always recommended to avoid using auto_ptr with arrays.&lt;/p&gt; &lt;p&gt;There are&amp;nbsp;few solutions proposed for this problem by Herb Sutter &lt;a href="http://www.gotw.ca/gotw/042.htm"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4360494515281350508?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4360494515281350508' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4360494515281350508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4360494515281350508'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/07/don-ever-mix-arrays-with-autoptr.html' title='Don&amp;#39;t ever mix Arrays with auto_ptr !'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-1625513146549259180</id><published>2007-07-08T15:04:00.002+05:30</published><updated>2009-10-24T16:16:10.406+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>C++0x</title><content type='html'>&lt;p&gt;The next&amp;nbsp;version of C++!&lt;/p&gt; &lt;p&gt;Bjarne offers a sneak peek at the next version of standard C++ ("C++0x") which should be complete by 2009.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.artima.com/cppsource/cpp0x.html"&gt;C++0x&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-1625513146549259180?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=1625513146549259180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1625513146549259180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/1625513146549259180'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/07/c0x.html' title='C++0x'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8147308238935876915</id><published>2007-07-08T14:43:00.002+05:30</published><updated>2009-10-24T16:16:27.496+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Smart Pointers'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Smart Pointers</title><content type='html'>&lt;p&gt;"Smart Pointers" Why do we need it?&lt;/p&gt; &lt;p&gt;It behaves like a pointer but does more than that. If used properly, it can enhance the code robustness, reduce memory leak headaches.&amp;nbsp;&lt;/p&gt; &lt;p&gt;What more does it do?&lt;/p&gt; &lt;p&gt;Consider a scenario, where&amp;nbsp;we&amp;nbsp;&amp;nbsp;use dynamic memory allocations&amp;nbsp;extensively.&amp;nbsp;We need to keep track of each allocation we did, for freeing&amp;nbsp;it back&amp;nbsp;to the system after its usage. if we forget, sure there will be a leak. &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void SomeFunction()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSomeClass *ptr = new CSomeClass();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr-&amp;gt;MemberFunction();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return; // Usual mistake! forgot to free memory. Leak!&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Consider&amp;nbsp;another case, where we allocated&amp;nbsp;memory dynamically but the statement&amp;nbsp;next to&amp;nbsp;that thrown an exception. It contributes for a memory leak, unless the exception is caught and the memory&amp;nbsp;is freed.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void SomeFunction()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CSomeClass *ptr = new CSomeClass();  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ptr-&amp;gt;MemberFunction(); // If this function throws exception, memory pointed by ptr won't be freed unless this is caught and freed  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;One more case for analysis,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;CSomeClass* ptr = new CSomeClass();&lt;br&gt;CSomeClass* otherptr = ptr;  &lt;p&gt;...  &lt;p&gt;ptr-&amp;gt;SomeFunction();  &lt;p&gt;...  &lt;p&gt;delete ptr;&lt;br&gt;ptr = NULL;&amp;nbsp;&amp;nbsp;&amp;nbsp; // ptr - used and safely deleted  &lt;p&gt;...  &lt;p&gt;otherptr-&amp;gt;SomeFunction();&amp;nbsp;&amp;nbsp; // Dangerous! otherptr is dangling&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;All these can happen with developers' small negligence. Using Smart pointer can avoid such nasty situations.&lt;/p&gt; &lt;p&gt;How?&lt;/p&gt; &lt;p&gt;Let's have a look at &lt;strong&gt;auto_ptr&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;auto_ptr&lt;/strong&gt; is one of the smart pointer templated class in Standard C++ library. It encapsulate a pointer. To embed any primitive or user defined pointer type, it has been made a templated class.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;template&amp;lt;class T&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class auto_ptr &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {  &lt;p&gt;public:  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; auto_ptr(T *p = 0);&amp;nbsp;&amp;nbsp;&amp;nbsp; // Constructor&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; auto_ptr(const auto_ptr&amp;lt;T&amp;gt;&amp;amp; Y); // Copy constructor &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~auto_ptr()&amp;nbsp;&amp;nbsp;&amp;nbsp; // Destructor&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete ptr;&amp;nbsp; // free the memory&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...  &lt;p&gt;private:  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; T *ptr;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }; &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;On executing the constructor of this, it takes the ownership of the &amp;nbsp;memory pointed by the pointer. Since the instance of the auto_ptr is crated on stack, the developer need not worry about freeing the memory.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;void function()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; auto_ptr&amp;lt;CSomeClass&amp;gt; smartPtr(new CSomeClass());&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Use smartPtr &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // No need to worry about freeing the memory&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // When the SmartPtr goes out of scope, will call the auto_ptr's destructor which will in turn delete the embedded ptr&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Even if there is an exception thrown before cleaning up, stack-unwinding will initiate the auto_ptr's destructor which will in turn free the memory. &lt;/p&gt; &lt;p&gt;Next question is how will we be able to use the smart pointer as a pointer. I mean we should be able to do the following things normally as we were doing with mere pointers,&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;smartPtr-&amp;gt;SomeFunction();&lt;br&gt;*smartPtr = 3;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;strong&gt;auto_ptr&lt;/strong&gt; has few more overloaded functions, which facilitates us to achieve this.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;T&amp;amp; operator*() const&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return *ptr;&lt;br&gt;}  &lt;p&gt;T *operator-&amp;gt;() const&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ptr;&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;These two operator overloaded functions enable us to use smartPtr as regular pointer. operator *() will help in dereferencing the pointer and operator-&amp;gt;() will do the indirection job.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.gotw.ca/publications/using_auto_ptr_effectively.htm"&gt;Article about auto_ptr at gotw&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8147308238935876915?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8147308238935876915' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8147308238935876915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8147308238935876915'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/07/smart-pointers.html' title='Smart Pointers'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-2616477773815501982</id><published>2007-06-30T14:44:00.001+05:30</published><updated>2009-10-24T16:16:47.721+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Library'/><category scheme='http://www.blogger.com/atom/ns#' term='DLL'/><title type='text'>Library - Reusable binary component</title><content type='html'>&lt;p&gt;In our daily development activities, we will come across various types of libraries. Like Static Library, Dynamic Linked Library, Plugins etc,&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In this article, I have tried to explain each of these.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;You consider any type of library, final objective will remain the same - &lt;strong&gt;Binary Reusability.&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Developer should identify a set of re-usable components or routines in his module and create a library. So that, this can be distributed and used by anyone instead of rewriting the components again.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Lets start from &lt;strong&gt;Static Library&lt;/strong&gt;(.lib) (called as &lt;strong&gt;Archive&lt;/strong&gt; in unix world). Usually libraries will be create with .lib extension (.a in unix). The idea behind static library is to create a reusable binary module that can be linked with any executable or another dynamic library, so that it can reuse the static library components. Linking/Binding module will have the responsibility of linking your executable with the static library. Hence the final size of the executable will be original executable code size + the static library code size. The executable will embed the static library within.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_ZmriMFhfr-Y/RoYfTf0E7tI/AAAAAAAAABY/HiBXJ27m51E/s1600-h/StaticLib.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_ZmriMFhfr-Y/RoYfTf0E7tI/AAAAAAAAABY/HiBXJ27m51E/s320/StaticLib.JPG" alt="" id="BLOGGER_PHOTO_ID_5081783649352085202" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; All the routines and components which were present in the static library can be directly used as if they were implemented in the same module.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;After compilation, at link time the linker module will look for all the symbols which were referenced in the executable and tries to link the static library. The developer has to specify the static library so that the linker can link it with the executable.&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Dynamically Linked Library (DLL)&lt;/strong&gt;:  Generally we export functions or routines from DLLs. When we say export that means those are all the entry points for the executables that are linked with it. Only the exported functions can be accessed by the executables.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;We can use the DLLs in two ways. One way is to link the static interface of a DLL with an executable and another is to load the DLL at run-time. Both have its own advantages. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Statically linking the DLL interface &lt;/strong&gt;: For any DLL, there will always be a static library(.lib) generated. This static library is just an interface to the DLLs exported functions, they wont have any definitions for the exported functions. They are just like routers to the actual definition which is present in the DLL. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Executables can link to this static library and use the exported functions in the DLL. The executable will just have DLLs interface embedded in it. DLL will be a separate module which will be loaded by the loader when we start the executable.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_ZmriMFhfr-Y/RoYgm_0E7uI/AAAAAAAAABg/d4wG31jXKg8/s1600-h/DLL.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_ZmriMFhfr-Y/RoYgm_0E7uI/AAAAAAAAABg/d4wG31jXKg8/s320/DLL.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5081785083871162082" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In this method, the DLL will be loaded when we start the executable. The life span of the exe along with the DLL can be depicted as below,&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_ZmriMFhfr-Y/RoYg2v0E7vI/AAAAAAAAABo/3Zli_1haCRE/s1600-h/SDLL.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_ZmriMFhfr-Y/RoYg2v0E7vI/AAAAAAAAABo/3Zli_1haCRE/s320/SDLL.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5081785354454101746" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Loading a DLL at Run-time &lt;/strong&gt;: This is the second way of using a DLL. Where we can use certain System API's to load the DLL at run-time. The static interface for the DLL is not used in this case. A typical example is shown below.&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;// Load the library&lt;br /&gt;MyDll = LoadLibrary("C:\\MyWork\\aDll.dll");  &lt;br /&gt;&lt;/p&gt;&lt;p&gt;// Get address of exported function&lt;br /&gt;FuncPointer = GetProcAddress(MyDll, "SomeExportedFunc");&lt;br /&gt;&lt;/p&gt;&lt;p&gt;// Make call&lt;br /&gt;FuncPointer();  &lt;br /&gt;&lt;/p&gt;&lt;p&gt;// Release the library&lt;br /&gt;FreeLibrary(MyDll)&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Note here that, the DLL can be loaded and released at any point of time with in the life span of the exe. Which is different from the previous method where it would load it at the start of the execution itself.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_ZmriMFhfr-Y/RoYhEP0E7wI/AAAAAAAAABw/N7xl89cnJTs/s1600-h/DDLL.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_ZmriMFhfr-Y/RoYhEP0E7wI/AAAAAAAAABw/N7xl89cnJTs/s320/DDLL.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5081785586382335746" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;A Plugin is an extension to this method. Lets talk about this in further articles.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Cheers!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-2616477773815501982?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=2616477773815501982' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2616477773815501982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2616477773815501982'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/in-our-daily-development-activities-we.html' title='Library - Reusable binary component'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_ZmriMFhfr-Y/RoYfTf0E7tI/AAAAAAAAABY/HiBXJ27m51E/s72-c/StaticLib.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4081107507542999187</id><published>2007-06-29T22:02:00.002+05:30</published><updated>2009-10-24T16:02:13.901+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Can access a private function?</title><content type='html'>&lt;p&gt;Today, at lunch time, Anand had a slip in his hand with C++&amp;nbsp;code written on it.&amp;nbsp;He was smiling showing that to me and asking to tell how the code behaves.&lt;/p&gt; &lt;p&gt;As usual he had a great feeling of discovering some new thing ;)&lt;/p&gt; &lt;p&gt;I had to watch the code,&amp;nbsp;it goes like below&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Class CBase&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual void vfunc()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Some definition&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;};  &lt;p&gt;&amp;nbsp;  &lt;p&gt;Class CDerived : public CBase&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void vfunc()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Some definition&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;};  &lt;p&gt;&amp;nbsp;  &lt;p&gt;int main()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CBase *pBase = new CDerived();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pBase-&amp;gt;vfunc();&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;CBase has a virtual function &lt;strong&gt;vfunc&lt;/strong&gt; which is overridden in CDerived. In the main routine we are making a base pointer to point to the derived class instance. Then we are calling the &lt;strong&gt;vfunc&lt;/strong&gt;.&lt;/p&gt; &lt;p&gt;The main point to note here is - CDerived::vfunc() is private.&lt;/p&gt; &lt;p&gt;Even&amp;nbsp;the function is declared as private&amp;nbsp;its accessible! when we do &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;pBase-&amp;gt;vfunc();&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Strange!&lt;/p&gt; &lt;p&gt;This is because the real call to the function is made thru virtual pointer. &lt;/p&gt; &lt;p&gt;We wouldn't be able to access the same function via an instance of CDerived. Isn't it? &lt;/p&gt; &lt;p&gt;What to say about this? Is this a design flaw? A loop hole? or just say &lt;strong&gt;"This is what C++ is"&lt;/strong&gt;!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4081107507542999187?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4081107507542999187' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4081107507542999187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4081107507542999187'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/can-access-private-function.html' title='Can access a private function?'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-810907235527315748</id><published>2007-06-24T18:39:00.002+05:30</published><updated>2009-10-24T16:17:08.579+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='dynamic_cast'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>dynamic_cast</title><content type='html'>&lt;p&gt;Lets talk about &lt;strong&gt;Dynamic Casting&lt;/strong&gt; today! &lt;br /&gt;&lt;p&gt;dynamic_cast is one of the&amp;nbsp;four C++ casting operators (static_cast, dynamic_cast, reinterpret_cast and const_cast), extensively used in case of polymorphic types. &lt;br /&gt;&lt;p&gt;Unlike C type casting which does a static type check, this will do a type check at run time. If the casting is invalid, it either throws bad_cast exception or returns a NULL pointer. &lt;br /&gt;&lt;p&gt;This has to be used for safe run-time down casting. &lt;br /&gt;&lt;p&gt;What is Down casting? &lt;br /&gt;&lt;p&gt;Casting a superclass pointer (or reference) into a pointer (or reference) to a subclass in a class hierarchy is said to be down casting. &lt;br /&gt;&lt;p&gt;Typical example looks like this, &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;CDerived *pD = dynamic_cast&amp;lt;CDerived *&amp;gt;pB; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;When to use? &lt;br /&gt;&lt;p&gt;Consider the scenario below, &lt;br /&gt; &lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_ZmriMFhfr-Y/Rn5t1l-n_3I/AAAAAAAAABM/W9zNv1Cyjak/s1600-h/DynamicCast.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_ZmriMFhfr-Y/Rn5t1l-n_3I/AAAAAAAAABM/W9zNv1Cyjak/s320/DynamicCast.jpg" alt="" id="BLOGGER_PHOTO_ID_5079618197215772530" border="0"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt; &lt;br /&gt;&lt;p&gt;Where the CControlIface is an abstract base class with a pure virtual function Draw(). There are two concrete classes implementing the CControlIface interface, CButtonControl and CTextControl which overrides the Draw()'s implementation. Also, they have their own methods &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;CButtonControl::OnClick()&lt;br&gt;CTextControl::OnKeyTyped() &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The problem is how will we identify the type of object pointed at run-time, if we just have the base class pointer or reference? &lt;br /&gt;&lt;p&gt;The solution is dynamic_casting &lt;br /&gt;&lt;p&gt;Let's look into some code. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;CControlIface *pControl1 = new CButtonControl();&lt;br&gt;CControlIface *pControl2 = new CTextControl(); &lt;br /&gt;&lt;p&gt;...&lt;br&gt;... &lt;br /&gt;&lt;p&gt;ProcessButtonEvent(pControl1);&lt;br&gt;// No idea what pControl1 points to, at compile time &lt;br /&gt;&lt;p&gt;...&lt;br&gt;... &lt;br /&gt;&lt;p&gt;void ProcessButtonEvent(CControlIface *pControl)&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Here we need make sure safe down-cast happens&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CButtonControl *pButton = dynamic_cast &amp;lt;CButtonControl *&amp;gt; pControl; &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // casting works fine here since we had passed pControl1 &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(pButton != NULL)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pButton-&amp;gt;OnClick();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We can now safely call OnClick() of CButtonControl&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;What would have happened if we had passed pControl2 while calling ProcessButtonEvent()? &lt;br /&gt;&lt;p&gt;dynamic_cast would have failed since pControl2 is not pointing to CButtonControl's instance. This check is performed by dynamic_cast operator at run-time using RTTI (Run-time Type Information). &lt;br /&gt;&lt;p&gt;Dynamic casting allows us to perform safe type conversions and lets our programs take appropriate actions when such casts fail. &lt;br /&gt;&lt;p&gt;Cheers!&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-810907235527315748?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=810907235527315748' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/810907235527315748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/810907235527315748'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/dynamiccast.html' title='dynamic_cast'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_ZmriMFhfr-Y/Rn5t1l-n_3I/AAAAAAAAABM/W9zNv1Cyjak/s72-c/DynamicCast.jpg' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8716634410406064255</id><published>2007-06-17T16:48:00.001+05:30</published><updated>2009-10-24T16:17:40.913+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='operator new'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>What's "new"?</title><content type='html'>Today's article talks about the &lt;span style="font-weight:bold;"&gt;new&lt;/span&gt;, which is an essential operator in C++ for dynamically instantiating an object.&lt;br /&gt;&lt;br /&gt;Why do we need new operator?&lt;br /&gt;There's a lot of difference between C's &lt;span style="font-weight:bold;"&gt;malloc&lt;/span&gt; and &lt;span style="font-weight:bold;"&gt;new&lt;/span&gt;. It does more than just allocating memory. It also calls the constructor. Which facilitates to initiate the object.&lt;br /&gt;&lt;br /&gt;Believe me, &lt;span style="font-weight:bold;"&gt;operator new&lt;/span&gt; and &lt;span style="font-weight:bold;"&gt;new operator&lt;/span&gt; are completely different!&lt;br /&gt;When we instantiate an object&lt;br /&gt; CTest *pObj = new CTest();&lt;br /&gt;&lt;br /&gt;This calls global &lt;span style="font-weight:bold;"&gt;new operator&lt;/span&gt; which performs 2 main tasks&lt;br /&gt; 1. Call &lt;span style="font-weight:bold;"&gt;operator new&lt;/span&gt; for allocating memory.&lt;br /&gt; 2. Call constructor of the particular object.&lt;br /&gt;&lt;br /&gt;We can always overload &lt;span style="font-weight:bold;"&gt;operator new&lt;/span&gt; which performs memory allocation operations. But we cannot change the meaning of the global &lt;span style="font-weight:bold;"&gt;new operator&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Typical example where we overload &lt;span style="font-weight:bold;"&gt;operator new&lt;/span&gt; will be in case of &lt;span style="font-weight:bold;"&gt;placement new&lt;/span&gt; where we change the actual meaning of &lt;span style="font-weight:bold;"&gt;operator new&lt;/span&gt; by passing address of memory where it has to instantiate the object.&lt;br /&gt;&lt;br /&gt;Let's talk about &lt;span style="font-weight:bold;"&gt;placement new&lt;/span&gt; in forth coming articles.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8716634410406064255?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8716634410406064255' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8716634410406064255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8716634410406064255'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/whats-new.html' title='What&apos;s &quot;new&quot;?'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-8031965856081431020</id><published>2007-06-12T17:56:00.001+05:30</published><updated>2009-10-24T16:18:04.181+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='constructors'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Conceptual "Virtual Constructors"</title><content type='html'>&lt;p&gt;In one of my old &lt;a href="http://prashanth-cpp.blogspot.com/2007/01/why-cant-we-have-virtual-constructors.html"&gt;article&lt;/a&gt; I had said that we cannot make the constructors virtual. &lt;br /&gt;&lt;p&gt;But its possible to have Conceptual &lt;span style="font-weight: bold"&gt;Conceptual "Virtual Constructors"&lt;/span&gt;. You might be wondering what do I mean by conceptual here? &lt;br /&gt;&lt;p&gt;Consider following code snippet, &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CAccountIface&lt;br&gt;{ &lt;br /&gt;&lt;p&gt;}; &lt;br /&gt;&lt;p&gt;class CSavingsAccount : public CAccountIface&lt;br&gt;{ &lt;br /&gt;&lt;p&gt;}; &lt;br /&gt;&lt;p&gt;class CCreditAccount : public CAccountIface&lt;br&gt;{ &lt;br /&gt;&lt;p&gt;}; &lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;And I have one more class which will have a list of accounts &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CBank&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CAccountIface* CreateAccount(int iAccType);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::vector&amp;lt;CAccountIface *&amp;gt; m_Accounts;&lt;br&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;Here the member function CAccountIface* CBank:: CreateAccount(int iAccType) acts like a virtual constructor. Depending on the type the user passes either the constructor for CSavingsAccount or CCreditAccount will be called and respective object will be instantiated. This behaves like a virtual constructor. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;We can even establish &lt;span style="font-style: italic"&gt;virtualism&lt;/span&gt; in case of copy constructors. &lt;br /&gt;&lt;p&gt;Let's try writing a copy c'tor for CBank class. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;CBank::CBank(const CBank &amp;amp;AnotherBank)&lt;br&gt;{ &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(std::vector&amp;lt;CAccountIface *&amp;gt;::size_type i = 0; i &amp;lt; AnotherBank.m_Accounts.size(); ++i )&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this-&amp;gt;m_Accounts[i] = AnotherBank.m_Accounts[i]-&amp;gt;Clone();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;I guess u'll already be wondering about the implementation for clone() member function. &lt;br /&gt;&lt;p&gt;Clone() has to be a pure virtual function in CAccountIface, and we can override this in CSavingsAccount and CCreditAccount to clone itself. &lt;br /&gt;&lt;p&gt;So the updated code will be as shown below, &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CAccountIface&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual CAccountIface *Clone() = 0;&lt;br&gt;}; &lt;br /&gt;&lt;p&gt;class CSavingsAccount : public CAccountIface&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual CSavingsAccount *Clone(){ return new CSavingsAccount(*this);} &lt;br /&gt;&lt;p&gt;}; &lt;br /&gt;&lt;p&gt;class CCreditAccount : public CAccountIface&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; virtual CCreditAccount *Clone(){ return new CCreditAccount(*this);} &lt;br /&gt;&lt;p&gt;}; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;When we say &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;m_Accounts[i]-&amp;gt;Clone(); &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The Clone() function will be called based on the type of object pointed by the pointer m_Accounts[i]. &lt;br /&gt;&lt;p&gt;This concept is also referred to as &lt;span style="font-weight: bold"&gt;"Factory Pattern"&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-8031965856081431020?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=8031965856081431020' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8031965856081431020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/8031965856081431020'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/conceptual-virtual-constructors.html' title='Conceptual &quot;Virtual Constructors&quot;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-6132253421239330418</id><published>2007-06-02T11:45:00.001+05:30</published><updated>2009-10-24T16:18:22.337+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Static &amp; Dynamic memory allocations...</title><content type='html'>I thought of writing this article since it was quite interesting even though it sounds as basic and primitive.&lt;br /&gt;&lt;br /&gt;Last night when I was coming back to home on Company's shuttle, my mate Debendra had few C++ questions for me.&lt;br /&gt;&lt;br /&gt;He asked "If I create a variable on stack say, &lt;span style="font-style:italic;"&gt;int i;&lt;/span&gt; and if I say &lt;span style="font-style:italic;"&gt;char *p = new char;&lt;/span&gt;. When will be the memory gets allocated? What time? Is it run-time or compilation time?"&lt;br /&gt;&lt;br /&gt;I had to say "All allocations happen only when you run the program, compiler will just compile the C++ code to instructions which will allocate the memory required on heap/stack"&lt;br /&gt;&lt;br /&gt;Then I got an unexpected question from him - "Then why do we say &lt;span style="font-style:italic;"&gt;int i;&lt;/span&gt; as static allocation and &lt;span style="font-style:italic;"&gt;char * p = new char&lt;/span&gt; as dynamic allocation, even though all allocations are happening at run-time?"&lt;br /&gt;&lt;br /&gt;A crazy question!&lt;br /&gt;&lt;br /&gt;Such a primitive and basic doubt every one may get and get confused.&lt;br /&gt;&lt;br /&gt;All allocations whether it may be dynamic or static happens at run-time only. But how the allocation is done matters.&lt;br /&gt;&lt;br /&gt;Let’s take the static allocation,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;int i;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;when compiler compiles this code, compiler knows what the size of &lt;span style="font-style:italic;"&gt;int&lt;/span&gt; is and it knows what number of bytes needs to be allocate at compilation time only. It generates instructions to allocate those many bytes, so that at run-time those many bytes are allocated.&lt;br /&gt;&lt;br /&gt;In case of dynamic allocation,&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;char *p = new char(n);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Compiler wont have any idea what is &lt;span style="font-style:italic;"&gt;n&lt;/span&gt;, it may be a function parameter or a value evaluated by an expression or even it can be a constant value, but at compilation time it has no idea what may be the number of bytes allocated. This can be dynamically configured and controlled at run-time.&lt;br /&gt;&lt;br /&gt;Importantly, in case of dynamic allocation, the amount of memory allocated is determined by the program at the time of allocation and need not be known in advance.&lt;br /&gt;&lt;br /&gt;Hence we say this as dynamic allocation.&lt;br /&gt;&lt;br /&gt;Hope Debendra had got his doubt cleared.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-6132253421239330418?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=6132253421239330418' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6132253421239330418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6132253421239330418'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/06/static-dynamic-memory-allocations.html' title='Static &amp; Dynamic memory allocations...'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-9120408367368120662</id><published>2007-05-31T09:24:00.000+05:30</published><updated>2007-05-31T09:31:39.720+05:30</updated><title type='text'>Const Correctness</title><content type='html'>I recently found a good article by Herb Sutter on Const-Correctness, a powerful feature of C++. This article talks about when to use const and when not to use it. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.gotw.ca/gotw/006.htm"&gt;Const Correctness by Herb Sutter&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Very interesting!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-9120408367368120662?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=9120408367368120662' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/9120408367368120662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/9120408367368120662'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/05/const-correctness.html' title='Const Correctness'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-591173002433637099</id><published>2007-05-24T21:48:00.000+05:30</published><updated>2007-05-24T22:01:49.494+05:30</updated><title type='text'>Resolving function address ...</title><content type='html'>The question is, if we are calling a function 'void function()' from 'main()', how the call is actually made?&lt;br /&gt;&lt;br /&gt;We know the answer, it will be just a jump instruction to a particular address where the function instruction set starts.&lt;br /&gt;&lt;br /&gt;How the member function address resolved in C++? &lt;br /&gt;&lt;br /&gt;We all know member function is not stored as part of the class. It will be stored outside somewhere (code segment?). Then how is the call made when we say 'obj.function()'?&lt;br /&gt;&lt;br /&gt;The answer is simple, actual call made would be like 'function(&amp;obj)'. Thereby it will be just a simple jump instruction as we saw earlier.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-591173002433637099?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=591173002433637099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/591173002433637099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/591173002433637099'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/05/resolving-function-address.html' title='Resolving function address ...'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-2657459404387599785</id><published>2007-03-14T17:05:00.001+05:30</published><updated>2009-10-24T16:18:45.459+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='constructors'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Calling ctor!!</title><content type='html'>&lt;p&gt;Well, suppose we have a class as below &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CTest&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTest()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;"ctor called!";&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}; &lt;br /&gt;&lt;p&gt;int main()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CTest();&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Does it mean c'tor can be called without creating an object? &lt;br /&gt;&lt;p&gt;Nope!! ofcourse not!! &lt;br /&gt;&lt;p&gt;The reason is when CTest(); is called, the compiler inserts the code to create a tempory object of CTest and calls its c'tor. Also it destroys the object right after executing CTest(); statement. &lt;br /&gt;&lt;p&gt;That is the reason calling constructor inside another constructor is not valid.&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-2657459404387599785?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=2657459404387599785' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2657459404387599785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/2657459404387599785'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/03/calling-ctor.html' title='Calling ctor!!'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-954841514477488248</id><published>2007-01-16T23:36:00.000+05:30</published><updated>2007-06-24T19:58:01.665+05:30</updated><title type='text'>delete this;</title><content type='html'>&lt;p&gt;"delete this;" legal? &lt;br /&gt;&lt;p&gt;Yes! of course its legal, with certain restrictions. &lt;br /&gt;&lt;p&gt;Once you call 'delete this;' no member variables should be accessed, since they would have been deleted already. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CTest&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int iInt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *iStr; &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void func()&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete this; // object destroyed here &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iInt = 6;// Illegal! don't do this&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Also this is not valid if the object is created on stack. Following should not be done. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;CTest obj;&lt;br&gt;obj.func(); // Not valid since obj is on stack &lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;&lt;p&gt;CTest *ptr = new CTest();&lt;br&gt;ptr-&amp;gt;func(); &lt;/p&gt;&lt;br /&gt;&lt;p&gt;// Valid, only if no members are accessed after delete this; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;One more interesting fact! What if we use 'delete this;' in destructor? ;)&lt;br&gt;Of course it will create the recursion calls to destructor!!! &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;&lt;p&gt;Is there any practical use of this then? &lt;br /&gt;&lt;p&gt;Yes! &lt;br /&gt;&lt;p&gt;Consider the scenario where I would want to restrict the user to be able to create an object only on heap. User should not be able to create the object on stack. &lt;br /&gt;&lt;p&gt;We can achieve this by making destructor private. There by preventing the stack unwinding to happen, which will intern avoid creating variables on stack. Then the user will only be able to create object on heap. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class COnlyOnHeap&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~COnlyOnHeap(); // destructor made private&lt;br&gt;}; &lt;br /&gt;&lt;p&gt;COnlyOnHeap obj; // Not possible since d'tor is private.&lt;br&gt;COnlyOnHeap *ptr= new COnlyOnHeap(); // Possible &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;We achieved our goal!&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Object can only be created on heap but not on stack. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;But, Wait! &lt;br /&gt;&lt;p&gt;How will u cleanup this?&lt;/p&gt;&lt;br /&gt;&lt;p&gt;We cannot say "delete ptr", because d'tor is private.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;How will we cleanup this then?&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The only way is to expose one more &lt;em&gt;cleanup&lt;/em&gt; public function which does "delete this;"! &lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;COnlyOnHeap::Cleanup()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete this; // This calls the private d'tor within the class&lt;br&gt;} &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Enjoy C++&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-954841514477488248?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=954841514477488248' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/954841514477488248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/954841514477488248'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/delete-this.html' title='delete this;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-4179186778327544885</id><published>2007-01-16T22:07:00.001+05:30</published><updated>2009-10-24T16:19:31.878+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Implementing a "final" class in C++</title><content type='html'>&lt;p&gt;The key word "final" exists in java world. It means, no class can inherit from the class declared as "final". A class which cannot be inherited further. &lt;br /&gt;&lt;p&gt;The simple method by which we can achieve this is to make the constructor of the class private. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CFinal&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CFinal(); // Private constructor to avoid inheritance &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static CFinal *GetInstance(); &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // static public member function to create the instance&lt;br&gt;}; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;This method looks very simple. If we try to derive another class from CFinal and try to instantiate that class, compiler errors out saying cant access CFinal's constructor, since its private. &lt;br /&gt;&lt;p&gt;But, this method has its own drawbacks, &lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Need to have a static public member function to create instance.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If the class needs to have more than one type of c'tors, all these c'tors need to be replaced by corresponding version of static-public-member function.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Object cannot be instantiated on stack. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;What if we make destructor private, instead of c'tors?&lt;br&gt;We can achieve the "final" thing.&lt;br&gt;But, this too cannot be instantiated on stack (stack-unwinding needs d'tors to be public). &lt;/p&gt;&lt;br /&gt;&lt;p&gt;We can club private d'tors, private c'tors, friend-class and virtual inheritance concepts to achieve a good solution. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class CFinal;&amp;nbsp; // Forward declaration&lt;br /&gt;&lt;p&gt;class CFinalLocker&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CFinalLocker();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~CFinalLocker(); &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; friend class CFinal;&lt;br&gt;}; &lt;br /&gt;&lt;p&gt;class CFinal : public virtual CFinalLocker&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;}; &lt;br /&gt;&lt;p&gt;class CDerived : public CFinal&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;} &lt;br /&gt;&lt;p&gt;CFinal objFinal; //OK - no problem&lt;br&gt;CDerived objDer; // Error! - Cant access CFinalLocker's c'tor &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Following is the useful explanation of the above technique &lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;CFinalLocker which is the base class for CFinal will have all of its c’tors and the destructor private.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;CFinal has been made friend of CFinalLocker. This is to facilitate CFinal to access all the members of CFinalLocker including members which are private. This will allow us to instantiate CFinal.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;We inherit our CFinal virtually from CFinalLocker. Now whenever anyone attempts to inherit class from CFinal and try to instantiate it, then its constructor tries to call the constructor of CFinalLocker. But the constructor of Temp is private so compiler complains about this and it gives error during the compilation, because your derived class is not friend of CFinalLocker. Remember friendship is not inherited in the derived class.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The purpose of inheriting CFinal virtually from CFinalLocker : the object of most derived class (whose object is created) directly calls the constructor of virtual base class (to avoid diamond problem). Now the most derived class (Bottom in case of diamond problem) directly calls the most base class (Top in diamond problem) constructor. So when we try instantiating CDerived compiler errors out since the c’tor in CFinalLocker is private.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-4179186778327544885?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=4179186778327544885' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4179186778327544885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/4179186778327544885'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/implementing-final-class-in-c.html' title='Implementing a &quot;final&quot; class in C++'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-145506865136555573</id><published>2007-01-12T11:06:00.000+05:30</published><updated>2007-01-12T11:07:21.458+05:30</updated><title type='text'>When do we need to have definition for a "Pure Virtual Function"?</title><content type='html'>Any answers?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-145506865136555573?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=145506865136555573' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/145506865136555573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/145506865136555573'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/when-do-we-need-to-have-definition-for_11.html' title='When do we need to have definition for a &quot;Pure Virtual Function&quot;?'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-9070675012781420344</id><published>2007-01-11T23:01:00.000+05:30</published><updated>2007-01-11T23:02:18.942+05:30</updated><title type='text'>Why can't we have "Virtual Constructors"?</title><content type='html'>Virtual mechanism acts on 'complete objects'.&lt;br /&gt;An object is complete 'after' the constructor has finished executing.&lt;br /&gt;So, it is illegal to make constructors virtual.&lt;br /&gt;Destructors can be virtual because by the time you apply them object has been constructed completely.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-9070675012781420344?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=9070675012781420344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/9070675012781420344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/9070675012781420344'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/why-cant-we-have-virtual-constructors.html' title='Why can&apos;t we have &quot;Virtual Constructors&quot;?'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-6740522758198628462</id><published>2007-01-11T22:56:00.000+05:30</published><updated>2007-01-11T22:58:54.561+05:30</updated><title type='text'>Need for "Virtual Destructor"</title><content type='html'>If we have 2 classes, say&lt;br /&gt;&lt;br /&gt;class CBase{&lt;br /&gt;public:&lt;br /&gt;CBase(){}&lt;br /&gt;~CBase(){}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class CDerived : public CBase{&lt;br /&gt;public:&lt;br /&gt;CDerived(){}&lt;br /&gt;~CDerived(){}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;and if we do,&lt;br /&gt;&lt;br /&gt;CBase* pBase = new CDerived;&lt;br /&gt;delete pBase;&lt;br /&gt;&lt;br /&gt;Since CBase does not have a virtual destructor, the delete pBase invokes the destructor of the class of the pointer (CBase::~CBase()), rather than the destructor of the most derived type (CDerived::~CDerived()). And as you can see, this is the wrong thing to do in the above scenario.&lt;br /&gt;&lt;br /&gt;A class must have a virtual destructor if it meets both of the following criteria:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;You do a delete pBase.&lt;/li&gt;&lt;li&gt;pBase actually points to a derived class object.&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-6740522758198628462?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=6740522758198628462' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6740522758198628462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/6740522758198628462'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/if-we-have-2-classes-say-class-cbase.html' title='Need for &quot;Virtual Destructor&quot;'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-7152896881859103690</id><published>2007-01-11T21:58:00.000+05:30</published><updated>2007-06-24T20:26:03.276+05:30</updated><title type='text'>Assignment operator Vs. Copy constructor</title><content type='html'>&lt;p&gt;The copy constructor is for creating a new object. It copies a existing object to a newly constructed object. &lt;br /&gt;&lt;p&gt;The assignment operator&amp;nbsp;is to deal with an already existing object. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;class MyObject&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public: &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyObject(); // Default constructor&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyObject(MyObject const &amp;amp; a); // Copy constructor &lt;br /&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Assignment operator&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyObject &amp;amp; operator = (MyObject const &amp;amp; a) &lt;br&gt;};&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;The copy constructors play an important role, as they are called when class objects are passed by value, returned by value, or thrown as an exception. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;// A function declaration with an argument of type MyObject,&lt;br&gt;// passed by value, and returning a MyObject &lt;br /&gt;&lt;p&gt;MyObject f(MyObject x) &lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyObject r;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(r); // Copy constructor is called here&lt;br&gt;} &lt;br /&gt;&lt;p&gt;// Calling the function : &lt;br /&gt;&lt;p&gt;MyObject a;&lt;br /&gt;&lt;p&gt;f(a); // Copy constructor called for "a" &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;It should be noted that the C++ syntax is ambiguous for the assignment operator. &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;MyObject x; x=y; &lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;and&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;MyObject x=y;&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;have different meaning.&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;MyObject a; // default constructor call &lt;br /&gt;&lt;p&gt;MyObject b(a); // copy constructor call &lt;br /&gt;&lt;p&gt;MyObject bb = a; // identical to bb(a) : copy constructor call &lt;br /&gt;&lt;p&gt;MyObject c; // default constructor call &lt;br /&gt;&lt;p&gt;c = a; // assignment operator call&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-7152896881859103690?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=7152896881859103690' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7152896881859103690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/7152896881859103690'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/assignment-operator-vs-copy-constructor.html' title='Assignment operator Vs. Copy constructor'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5883865168597393160.post-3901230634559007512</id><published>2007-01-11T21:50:00.000+05:30</published><updated>2007-06-24T20:32:54.503+05:30</updated><title type='text'>Overloading Vs. Overriding</title><content type='html'>&lt;li&gt;Overloading is nothing but static binding.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Overriding is dynamic binding which will be resolved at run-time. &lt;/li&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Overloading deals with multiple methods in the same class with the same name but different signatures.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature. &lt;/li&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Overloading lets you define a similar operation in different ways for different data.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Overriding lets you define a similar operation in different ways for different object types.&lt;/li&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5883865168597393160-3901230634559007512?l=prashanth-cpp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5883865168597393160&amp;postID=3901230634559007512' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3901230634559007512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5883865168597393160/posts/default/3901230634559007512'/><link rel='alternate' type='text/html' href='http://prashanth-cpp.blogspot.com/2007/01/overloading-vs-overriding.html' title='Overloading Vs. Overriding'/><author><name>Prashanth Narayanaswamy</name><uri>http://www.blogger.com/profile/17713594715167082598</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='26' height='32' src='http://1.bp.blogspot.com/_ZmriMFhfr-Y/SmiD-CAGl6I/AAAAAAAAATs/0Gn3joiKa4s/S220/p.JPG'/></author><thr:total>4</thr:total></entry></feed>
