<?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:blogger='http://schemas.google.com/blogger/2008' 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-5552992012603264667</id><updated>2024-10-04T19:05:31.970-07:00</updated><category term="coding everything"/><category term="c++"/><category term="codinpsycho"/><category term="ishkaran singh"/><category term="programming"/><category term="2d computer games"/><category term="2d game"/><category term="computer games"/><category term="constant pointers"/><category term="forward declaration c++"/><category term="game mechanics"/><category term="hge games download"/><category term="how to reduce compile time dependencies"/><category term="inheritance"/><category term="pointers"/><category term="this pointer"/><category term="virtual functions"/><category term="2d crysis"/><category term="2d vectors"/><category term="The siege"/><category term="andrew"/><category term="anime"/><category term="argc"/><category term="argument"/><category term="argv"/><category term="arrays"/><category term="class padding"/><category term="conflict"/><category term="dependent"/><category term="difference between function prototype and forward declaration"/><category term="different ways to use static"/><category term="exception"/><category term="file handling c++"/><category term="function declaration c++"/><category term="gaming"/><category term="geek"/><category term="haaf&#39;s game engine"/><category term="hidden this pointer in member functions"/><category term="how arrays work"/><category term="how main works"/><category term="how to move a sprite in a game"/><category term="ifstream"/><category term="implicit passing this pointer"/><category term="india"/><category term="indiedb"/><category term="koenig"/><category term="lookup"/><category term="macros"/><category term="main()"/><category term="marketing"/><category term="merchandise"/><category term="movement formula"/><category term="namespace"/><category term="ofstream"/><category term="opaque pointers"/><category term="padding in c"/><category term="passing arguments to main()"/><category term="passing by value"/><category term="pimpl"/><category term="pimpl idiom"/><category term="polymorphism"/><category term="psychostore"/><category term="reading a file c++"/><category term="reducing compile time"/><category term="remarkable"/><category term="return by value"/><category term="rule to inherit"/><category term="rules to inherit"/><category term="seth godin"/><category term="shanker sharma"/><category term="size of a class/structure"/><category term="static functions"/><category term="static keyword"/><category term="static variables"/><category term="stdarg.h"/><category term="stucture padding"/><category term="t shirts"/><category term="tees"/><category term="temporaries c++"/><category term="tshirts"/><category term="type mismatch"/><category term="understanding temporaries"/><category term="variable argument functions"/><category term="vectors"/><category term="vptr"/><category term="vtable"/><category term="what are arrays"/><category term="when temporaries are generated"/><category term="working of virtual functions"/><category term="writing a file c++"/><title type='text'>Codinpsycho</title><subtitle type='html'>I Game Hard, I Code Hard</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-168512519072396890</id><published>2016-02-15T07:38:00.003-08:00</published><updated>2016-02-18T23:54:34.332-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="anime"/><category scheme="http://www.blogger.com/atom/ns#" term="gaming"/><category scheme="http://www.blogger.com/atom/ns#" term="geek"/><category scheme="http://www.blogger.com/atom/ns#" term="india"/><category scheme="http://www.blogger.com/atom/ns#" term="marketing"/><category scheme="http://www.blogger.com/atom/ns#" term="merchandise"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="psychostore"/><category scheme="http://www.blogger.com/atom/ns#" term="remarkable"/><category scheme="http://www.blogger.com/atom/ns#" term="seth godin"/><category scheme="http://www.blogger.com/atom/ns#" term="t shirts"/><category scheme="http://www.blogger.com/atom/ns#" term="tees"/><category scheme="http://www.blogger.com/atom/ns#" term="tshirts"/><title type='text'>Understanding the art of being remarkable</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
This is not a post about being remarkable in life or some self help kind of advice, this is something that will make you realize how you can perceive the word &quot;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;remarkable&lt;/span&gt;&quot; a bit differently and more importantly how you can utilize that perception in improving your products and spreading your ideas to more and more people. Also I will give you examples of how I implemented this thing in&amp;nbsp;&lt;a href=&quot;http://psychostore.in/&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.298039); background-image: linear-gradient(rgba(68, 68, 68, 0) 50%, rgba(68, 68, 68, 0.247059) 50%); background-position: 0px 1.15em; background-repeat: repeat-x; background-size: 1em 2px; border: 0px; box-sizing: border-box; color: #444444; cursor: pointer; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px 0px 0.15em; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;psycho store&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;myself.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;media-holder media-holder-draggable media-holder-hr&quot; draggable=&quot;true&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; cursor: -webkit-grab; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin: 0px -20px; outline: none 0px; padding: 0px 20px; position: relative; vertical-align: baseline;&quot;&gt;
&lt;hr class=&quot;tmblr-truncated&quot; data-label=&quot;Keep reading&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; height: auto; margin: 15px auto; max-width: none; outline: none 0px; padding: 0px; position: relative; text-align: center; width: auto;&quot; /&gt;
&lt;div class=&quot;media-button icon_close media-killer&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; background-color: #d95e40; border-radius: 50%; border: 1px solid rgb(217, 94, 64); box-sizing: border-box; color: white; cursor: pointer; font-family: inherit; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; height: 21px; margin: 0px; opacity: 0; outline: none 0px; padding: 0px; pointer-events: none; position: absolute; right: -11px; text-align: center; top: -7px; transform: scale(0); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s cubic-bezier(0.165, 0.84, 0.44, 1); vertical-align: baseline; width: 21px;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
When someone says that something is remarkable, the first thing that comes to mind is something that is considered to be superior in its class, but what we fail to realize is that how remarkable can simply mean something that would force a person to make a &quot;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;remark&quot;&lt;/span&gt;&amp;nbsp;about it. Something that would make the user feel&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&quot;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Hey wait, this is something different!&lt;/i&gt;&quot;, so that he/she can later on tell his/her friend&lt;br /&gt;
&quot;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;You know that thing was different from what it was supposed to be.&lt;/i&gt;&quot; and that&#39;s how your product will advertise itself through word of mouth.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
I am not saying that your whole product needs to be remarkable, the key here is to make the experience of using the product remarkable. You have a finite set of interactions that the user will do with your product, now its up to you to make something happen in that interaction due to which it will get registered in the user&#39;s mind. The reason being that the user already has a set of expectations from your product, which comes from comparing your product to your competitors. Now a positive effect of getting noticed will be possible only in the case of you exceeding those already set expectations, failing which a remark may be generated but which will obviously be negative for you or majority of the time no remark at all. Let me explain what I mean by giving examples on how I utilized this myself when working on&amp;nbsp;&lt;a href=&quot;http://psychostore.in/&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.298039); background-image: linear-gradient(rgba(68, 68, 68, 0) 50%, rgba(68, 68, 68, 0.247059) 50%); background-position: 0px 1.15em; background-repeat: repeat-x; background-size: 1em 2px; border: 0px; box-sizing: border-box; color: #444444; cursor: pointer; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px 0px 0.15em; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;psycho store&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
So&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a href=&quot;http://psychostore.in/&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.298039); background-image: linear-gradient(rgba(68, 68, 68, 0) 50%, rgba(68, 68, 68, 0.247059) 50%); background-position: 0px 1.15em; background-repeat: repeat-x; background-size: 1em 2px; border: 0px; box-sizing: border-box; color: #444444; cursor: pointer; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px 0px 0.15em; text-decoration: none; vertical-align: baseline;&quot;&gt;Psycho Store&lt;/a&gt;&lt;/i&gt;&lt;/span&gt;&amp;nbsp;being yet another eCommerce clothing site, is bound to generate some fixed assumptions which the user have acquired after using other clothing sites. Now our job is to surpass those expectations in order to get the users attention. We just can&#39;t afford to remain plain old same, especially in the startup world.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
For eg: Now keep in mind that&amp;nbsp;&lt;a href=&quot;http://psychostore.in/&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.298039); background-image: linear-gradient(rgba(68, 68, 68, 0) 50%, rgba(68, 68, 68, 0.247059) 50%); background-position: 0px 1.15em; background-repeat: repeat-x; background-size: 1em 2px; border: 0px; box-sizing: border-box; color: #444444; cursor: pointer; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px 0px 0.15em; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;psycho store&lt;/span&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;is a brand that focuses on&amp;nbsp;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;gaming/anime&lt;/span&gt;&amp;nbsp;merchandises. So during checkout, when the user will be expecting to apply discount code, he/she will notice that there is no option for a discount code, but instead it asks for a &quot;cheat code&quot;, which will obviously strike a special chord in every gamer, and just by its side, there is a button named HINT!, you take your mouse over to that button and it says &quot;What is the Konami Code?&quot; Now if you remember the Contra&#39;s 31 lives cheat code, then well and good otherwise you google the code, do some trial and error and voila you get 10% off.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;media-holder media-holder-draggable media-holder-figure&quot; draggable=&quot;true&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; cursor: -webkit-grab; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin: 0px -20px; outline: none 0px; padding: 0px 20px; position: relative; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;figure class=&quot;tmblr-full&quot; data-orig-height=&quot;336&quot; data-orig-width=&quot;1160&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 20px -20px 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;img alt=&quot;image&quot; data-orig-height=&quot;336&quot; data-orig-width=&quot;1160&quot; src=&quot;https://41.media.tumblr.com/a1506a2c39b7a4dea91465ce18bc16b8/tumblr_inline_o2hq7iW1wa1tam79e_540.jpg&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; display: block; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; height: auto; line-height: inherit; margin: 0px; max-width: 100%; min-width: 100%; outline: none 0px; padding: 0px; pointer-events: none; vertical-align: baseline; width: 540px;&quot; /&gt;&lt;/figure&gt;&lt;br /&gt;
&lt;div class=&quot;media-button icon_close media-killer&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; background-color: #d95e40; border-radius: 50%; border: 1px solid rgb(217, 94, 64); box-sizing: border-box; color: white; cursor: pointer; font-family: inherit; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; height: 21px; margin: 0px; opacity: 0; outline: none 0px; padding: 0px; pointer-events: none; position: absolute; right: -11px; text-align: center; top: -7px; transform: scale(0); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s cubic-bezier(0.165, 0.84, 0.44, 1); vertical-align: baseline; width: 21px;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 20px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Now imagine the happiness in the users mind, he must be feeling as if he has unlocked some mystery or solved a puzzle just like he/she does in a game. Now simply by being a little different (in a better way) we managed to connect with the user&#39;s mind in a way that will make him remember us and narrate this experience to his friends who share similar interests.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Another example will be the confirmation mail that the user is expecting to get. But in psycho store along with the usual confirmation mail, you get another mail, once you start reading it you realize that its a short story with a cliffhanger ending and in the end it&#39;s written &quot;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;The Story continues on your next order&lt;/i&gt;&quot;. The best part was when I myself saw two people talking about&amp;nbsp;&lt;a href=&quot;http://psychostore.in/&quot; style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.298039); background-image: linear-gradient(rgba(68, 68, 68, 0) 50%, rgba(68, 68, 68, 0.247059) 50%); background-position: 0px 1.15em; background-repeat: repeat-x; background-size: 1em 2px; border: 0px; box-sizing: border-box; color: #444444; cursor: pointer; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px 0px 0.15em; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: 700; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;i style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; font-family: inherit; font-size: inherit; font-stretch: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;psychostore&lt;/i&gt;&lt;/span&gt;&amp;nbsp;&lt;/a&gt;in Instagram comments, saying &quot;Did you get that short story in the end, that was so cool.&quot; and the other person replying how &quot;he loved the thank you sticky note inside the box&quot; Now this proves that these memories stayed with them and made a positive impact on their mind. Now there are tons of other small things that we have added as well, like adding a small hand written thank you sticky note in the box or the packaging box itself which is a cylindrical box and not the usual polythene bags.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Showing some sales statistics on the site like the last order with a graph showing from which state most orders come or which game&#39;s merchandise sells the most, now the user is not used to getting this kind of information from similar sites, so when something like this happens, it makes the user alert and take note of it. Now I can either tell you all these things that we have implemented or you can go and experience it yourself, which in my opinion will be a better thing to do.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
The point that I am trying to make here is that it is not necessary to do exceptionally big out of the box things, you can achieve it by focusing on the small details that make up your whole experience. Now another important point to be kept in mind is that all these things need to gel together as a whole and should not feel like an odd one out thing, like we added the cheat code thing because we focus on gaming merchandises, if we were selling formal shoes, then cheat code won&#39;t have made much sense.&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Now imagine running naked down the street, it will surely get you noticed and a lot of people will remark about it right, but does it accomplish anything?&lt;/div&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; line-height: 21px; margin-bottom: 15px; margin-top: 15px; outline: none 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
With the multitude of options and information overwhelming our brain everyday and reducing our attention span, there is just no more room for being average anymore.&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; -webkit-text-stroke-width: 0px; border: 0px; box-sizing: border-box; color: #444444; font-family: &#39;Helvetica Neue&#39;, HelveticaNeue, Helvetica, Arial, sans-serif; font-size: 14px; font-stretch: inherit; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; margin: 15px 0px; orphans: auto; outline: none 0px; padding: 0px; text-align: left; text-indent: 0px; text-transform: none; vertical-align: baseline; white-space: normal; widows: 1; word-spacing: 0px;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
So go out and do something that&#39;s worthy of a remark. I will highly recommend this video by Seth Godin to understand the idea much better and to gain some new ones as well.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/168512519072396890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2016/02/understanding-art-of-being-remarkable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/168512519072396890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/168512519072396890'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2016/02/understanding-art-of-being-remarkable.html' title='Understanding the art of being remarkable'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-1317485694818018010</id><published>2011-12-23T10:22:00.000-08:00</published><updated>2011-12-23T10:22:14.726-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="andrew"/><category scheme="http://www.blogger.com/atom/ns#" term="argument"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="codinpsycho"/><category scheme="http://www.blogger.com/atom/ns#" term="conflict"/><category scheme="http://www.blogger.com/atom/ns#" term="dependent"/><category scheme="http://www.blogger.com/atom/ns#" term="exception"/><category scheme="http://www.blogger.com/atom/ns#" term="koenig"/><category scheme="http://www.blogger.com/atom/ns#" term="lookup"/><category scheme="http://www.blogger.com/atom/ns#" term="namespace"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>Koenig Lookup/ Argument -Dependent Lookup</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;Koenig Lookup/ Argument -Dependent Lookup&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;lets suppose the following scenario --&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;//Trivial namespace for testing purpose&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;namespace test&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;class A { };&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Empty Class&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;void f(int x) { &amp;nbsp;cout&amp;lt;&amp;lt;x; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//simply ouputs the integer value passd&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int f(A obj) { cout&amp;lt;&amp;lt;&quot;OBJECT&quot;; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Prints OBJECT and takes an object of class A&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;//Inside main() i make a simple function call&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;f(10);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;Now what will happen is that the compiler will search the global/free functions for&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;similar signature, but wont find one because there aint one. The function&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;void f(int x) is the namespace test and is inaccesible there until we use&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;using namespace test;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;Now if i add a function&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int f(int x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{ cout&amp;lt;&amp;lt;x; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;//Inside main() i make a simple function call&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;f(10);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;just before main() i.e in the global region, then the compiler will find a match when&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;called through main(). This is all so simple and obvious, isnt it?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;Now a similar case --&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;//Trivial namespace for testing purpose&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;namespace test&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;class A { };&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Empty Class&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;void f(int x) { &amp;nbsp;cout&amp;lt;&amp;lt;x; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//simply ouputs the integer value passd&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int f(A obj) { cout&amp;lt;&amp;lt;&quot;OBJECT&quot;; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Prints OBJECT and takes an object of class A&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int f(test::A obj) { cout&amp;lt;&amp;lt;&quot;ANOTHER OBJECT&quot;; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Similar to function inside namespace &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//but this one is just in global scope&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;//Inside main() i make a simple function call&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;test::A obj;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;f(obj);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #e06666; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;Now what will happen in this case. the obvious answer would be that global f() would be&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;called and ANOTHER OBJECT will be printed. but heres the truth guyz, the compiler will&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;deflect slightly from usual name-lookup and will use another kind of name-lookup because&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;the parameter you passed to the function is an object of a class/structure.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;This kind of name-lookup is called KOENIG LOOKUP/ARGUMENT DEPENDENT LOOKUP.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;and it would lead to an ambiguous call, the compiler would get confused between&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;test::f(A obj) and global int f(test::A obj)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;although theres no using directive used.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;The compiler will follow this rule ---&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #45818e; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&quot;If the parameter passed to a function is an object of a class/structure then the compiler&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #45818e; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #45818e; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;would also include those namespaces in which that class/structure or its object is&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #45818e; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #45818e; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;defined.&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;Well you would be thinking that whats the use of namespaces then, the namespaces are&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;still functional and continue to serve their purpose, but this is just one rare case in which&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;the compiler crosses the namespace boundary.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;This kind of lookup called KOENIG LOOKUP was named after &lt;span style=&quot;color: #45818e;&quot;&gt;&lt;b&gt;Andrew Koenig&lt;/b&gt;&lt;/span&gt; who nailed&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;its proper definition.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/1317485694818018010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/koenig-lookup-argument-dependent-lookup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/1317485694818018010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/1317485694818018010'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/koenig-lookup-argument-dependent-lookup.html' title='Koenig Lookup/ Argument -Dependent Lookup'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-9200449346392488820</id><published>2011-12-17T04:55:00.000-08:00</published><updated>2012-03-09T23:31:15.580-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="codinpsycho"/><category scheme="http://www.blogger.com/atom/ns#" term="forward declaration c++"/><category scheme="http://www.blogger.com/atom/ns#" term="how to reduce compile time dependencies"/><category scheme="http://www.blogger.com/atom/ns#" term="opaque pointers"/><category scheme="http://www.blogger.com/atom/ns#" term="pimpl"/><category scheme="http://www.blogger.com/atom/ns#" term="pimpl idiom"/><category scheme="http://www.blogger.com/atom/ns#" term="pointers"/><title type='text'>Using pimpl idiom C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;The Infamous pimpl idiom C++&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Pimpl standing for Private Implementation is a famous C++ idiom &amp;nbsp;particularly popularized in Herb Sutter&#39;s Guru of the week column (www.gotw.ca).&lt;br /&gt;
It describes a way for hiding your class&#39;s private members,by making them invisible from your Header file. Remeber this fact that whenever compiler sees your class, it only sees the header file (.h) and not the implementation file (.cpp). So what this basically does is that it removes all your private members from your header file(.h) and adds them to your implementation file (.cpp). Additional advantage of this technique is that it makes your class immune to changes meaning that you dont need to recompile it again and again if you change the private memebers. Also it keeps you public interface clean, and the client programmer doesn&#39;t need to be aware of you private members. It achieves this by using an opaque pointer, which is a pointer to a forward declared class or structure.&lt;br /&gt;
&lt;br /&gt;
Eg:&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;struct B_impl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Forward declared structure&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;class A {&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;B-impl *my_Impl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Opaque pointer&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Here Structure B-impl is only forward declared so the pointer my_Impl is an opaque pointer.&lt;br /&gt;
Now lets jump directly into action and see how pimpl is implemented :&lt;br /&gt;
&lt;br /&gt;
This is our class :&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;//file A.h&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;//So many header files increases compile time :(&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;A.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;B.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;C.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;D.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;vector&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;class A&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;{&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;B objB;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;C objC;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;vector vlist&amp;lt;D&amp;gt;;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now lets implement pimp idiom ---&amp;gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;//file A.h&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;//What happened to all the header files.....??&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;strcut pimpl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//forward declared structure&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;class A&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;{&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;pimpl *my_impl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//opaque pointer to implement pimpl&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;//file A.cpp&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;#include&amp;lt;A.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;strcut pimpl&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;{&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;B objB;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;C objC;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;vector vlist&amp;lt;D&amp;gt;;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So this is how we implement pimpl :&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #76a5af;&quot;&gt;1. forward declare some structure/class&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #76a5af;&quot;&gt;2. Make a pointer of that strcutrure/class known as opaque pointer&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #76a5af;&quot;&gt;3. Declare all the private members in the .cpp file inside the structure/class.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now the big question is that what should go inside the pimpl strcuture/class....??&lt;br /&gt;
Remember some basic points in mind while designing pimpl idiom.&lt;br /&gt;
---&amp;gt; Take all your non-virtual private members (variables + functions)&lt;br /&gt;
---&amp;gt; Never take protected members, because they were made protected at the first place so that the derived class can see them, if you hide them then whats the point of making them protected in the first place...??&lt;br /&gt;
---&amp;gt; Make your pimpl structure/class exactly as your class A would have been and make your class A just as a plain easy to use public interface with forwarding functions.&lt;br /&gt;
&lt;br /&gt;
But finally the question arrives &quot;was the pimpl implementation worth the pain...&quot;??&lt;br /&gt;
the question will always depend on the programmer who is implementing it. For what class he is implemeting it.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/9200449346392488820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/infamous-pimpl-idiom-c.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/9200449346392488820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/9200449346392488820'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/infamous-pimpl-idiom-c.html' title='Using pimpl idiom C++'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-1145446588777505522</id><published>2011-12-15T10:15:00.000-08:00</published><updated>2011-12-15T10:27:03.120-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="difference between function prototype and forward declaration"/><category scheme="http://www.blogger.com/atom/ns#" term="forward declaration c++"/><category scheme="http://www.blogger.com/atom/ns#" term="function declaration c++"/><category scheme="http://www.blogger.com/atom/ns#" term="how to reduce compile time dependencies"/><category scheme="http://www.blogger.com/atom/ns#" term="reducing compile time"/><title type='text'>How to reduce compile time dependencies</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
How to reduce compile time dependencies&lt;br /&gt;
&lt;br /&gt;
The main culprit behind compile time dependencies is the huge amount of header files that are included by the compiler. Header files that are required in the code will obviously be added, but some programmers out of just habit include some useless header files as well. For eg :&lt;br /&gt;
In this code few header file will not be reqired&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;//Header files:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#include&amp;lt;iostream&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#include&amp;lt;ostream&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#nclude&amp;lt;B.h&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#nclude&amp;lt;C.h&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#nclude&amp;lt;A.h&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;claas A {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;B *obj;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;C *obj;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;virtual std::ostream&amp;amp; print( std::ostream&amp;amp; ) const;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
From the above code we can remove B.h and C.h straight away and use forward declaration instead of includeing those header files. Now what the hell is this FORWARD DECLARATION...??&lt;br /&gt;
Forward declaration is when we just declare and dont define.&lt;br /&gt;
Suppose we are just using references or pointers to B or C, then we can get away with forward declaration and dont need to include the header files.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp; class B ;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Forward declaration only no need to include&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; class A {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; private:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; B* fPtrB ;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; public:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; void mymethod(const&amp;amp; B) const ;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; } ;&lt;/b&gt;&lt;br /&gt;
But if we derive from B or C or uses objects of B or C, then we need to include their header files.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;#include&amp;lt;B.h&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Header file included&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; class A : public B{&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; } ;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; class C {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; private:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; B objB ;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; public:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; void mymethod(B par) ; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; }&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Also we can remove #include&amp;lt;iostream&amp;gt; as well, dont be confused with the word stream, its not necessary that whenever you encounter the word stream you include &amp;lt;iostream&amp;gt;.&lt;br /&gt;
Here ostream is used and when can use #include&amp;lt;ostream&amp;gt; only and it will suffice.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So after clearing all the unwanted header files, heres what our code looks like :&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;//Header files:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#include&amp;lt;ostream&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;#nclude&amp;lt;A.h&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;claas A {&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;B *obj;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;C *obj;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;virtual std::ostream&amp;amp; print( std::ostream&amp;amp; ) const;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
One more thing we can do here is that we can use &amp;lt;iosfwd&amp;gt; instead of &amp;lt;ostream&amp;gt;,&lt;br /&gt;
what it will do is forward declare all the necessary things for ostream.&lt;br /&gt;
&lt;br /&gt;
Some of you might also be wondering that whats the difference between function prototype and forward declaration.&lt;br /&gt;
&lt;br /&gt;
In writing a function prototype you don&#39;t need to define parameter names, just their data type will suffice&lt;br /&gt;
int add( int, int );&lt;br /&gt;
but in forward declaration you need to specify their name as well,tough both will&amp;nbsp;fulfill&amp;nbsp;you requirements.&lt;br /&gt;
&lt;br /&gt;
1 more thing that might interest you guys is that, think what will happen when you only declare the function and don&#39;t define it and then call it.........???&lt;br /&gt;
&lt;br /&gt;
int add(int a, int b)&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;Sum of 5 and 10 is &quot;&amp;lt;&amp;lt;add(5,10);&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We have declared add but never defined it and also used it in our code...&lt;br /&gt;
So compiling will succeed but linking will fail and it will give error unresolved external symbol.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/1145446588777505522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/how-to-reduce-compile-time-dependencies.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/1145446588777505522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/1145446588777505522'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/how-to-reduce-compile-time-dependencies.html' title='How to reduce compile time dependencies'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-929404984894423926</id><published>2011-12-04T01:59:00.001-08:00</published><updated>2011-12-04T03:30:10.916-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="2d computer games"/><category scheme="http://www.blogger.com/atom/ns#" term="2d game"/><category scheme="http://www.blogger.com/atom/ns#" term="2d vectors"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="computer games"/><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics"/><category scheme="http://www.blogger.com/atom/ns#" term="hge games download"/><category scheme="http://www.blogger.com/atom/ns#" term="how to move a sprite in a game"/><category scheme="http://www.blogger.com/atom/ns#" term="ishkaran singh"/><category scheme="http://www.blogger.com/atom/ns#" term="movement formula"/><category scheme="http://www.blogger.com/atom/ns#" term="vectors"/><title type='text'>How to move something in games c++</title><content type='html'>&lt;meta name=&quot;msvalidate.01&quot; content=&quot;87BC2CF0025865B93D4F22FAD21AC156&quot; /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Movement in game programming&lt;br /&gt;
&lt;br /&gt;

I will be explaining you the basics of movement in 2D Games. Its a very simple concept which anyone can implement in their respective framework after understanding the basics.&lt;br /&gt;
Its done by repeatedly calculating new position from the previous coordinates. Its pure 2D vector maths, so u should be familiar with that also. So now here the is the formula known to Game programmers as&lt;br /&gt;
&amp;nbsp;&quot;MOVEMENT FORMULA&quot; :&lt;br /&gt;
&lt;br /&gt;
New position = Old position + Speed * Direction&lt;br /&gt;
&lt;br /&gt;
This is the basic formula which makes anything move in games.&lt;br /&gt;
If you want to move something in X direction, simply&lt;br /&gt;
&lt;br /&gt;
sprite.x = sprite.x + sprite.speed * sprite.direction;&lt;br /&gt;
&lt;br /&gt;
Similarly to move in Y direction :&lt;br /&gt;
&lt;br /&gt;
sprite.y = sprite.y + sprite.speed * sprite.direction&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
You have to move a bird from one side of the screen to other, in X axis only. So you set the starting coordinates to lets suppose (-10,0), set up its speed ,suppose 5 and direction 1 .&lt;br /&gt;
&amp;nbsp;Now lets apply this formula and move the bird.&lt;br /&gt;
bird.x = bird.x + bird.speed*bird.dir;&lt;br /&gt;
In the first frame:&lt;br /&gt;
-10 + 5*1 = 5&lt;br /&gt;
Next frame&lt;br /&gt;
-5 + 5*1 = 0&lt;br /&gt;
next frame&lt;br /&gt;
0 + 5*1 = 5;&lt;br /&gt;
and so on.....&lt;br /&gt;
&lt;br /&gt;
So bird will first be rendered at (-10,0)&lt;br /&gt;
in the next frame (-5,0) then (0,0) then (5,0) and so on......this will give you an illusion of movement of the bird.&lt;br /&gt;
If you want to make it move in the opposite direction simply take direction as -1.&lt;br /&gt;
&lt;br /&gt;
Now lets suppose you want to make it in a certain angle.&lt;br /&gt;
Simply move in both directions&lt;br /&gt;
Simultaneously change its X and Y co-ordinates.&lt;br /&gt;
Now lets get into VECTORS.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9cqSVfdZDQYpfKkytsxba6VrcTx9ttjrghH6gXRhl53L-3kUV9smCkbYnHJEYeMXvO4KVm6jJc0hA0W-SYi58JlNsLz4Z5wzEgViJUSclnPsLBh6H7o_f0bPCJVAhsvlgqVE_wOzfjs0/s1600/move.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;244&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9cqSVfdZDQYpfKkytsxba6VrcTx9ttjrghH6gXRhl53L-3kUV9smCkbYnHJEYeMXvO4KVm6jJc0hA0W-SYi58JlNsLz4Z5wzEgViJUSclnPsLBh6H7o_f0bPCJVAhsvlgqVE_wOzfjs0/s640/move.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Like in this image you want to get to a specific point like you have to move from A --&amp;gt; B&lt;br /&gt;
Then A will have some cordinates and it will be a vector, similarly B will be another vector&lt;br /&gt;
So now we have co-ordinates,speed but we dont know the direction, for that&lt;br /&gt;
&amp;nbsp;B - A = C&lt;br /&gt;
Normalizing that vector C will give us the direction, which we can then use in our movement fformula.&lt;br /&gt;
&lt;br /&gt;
The point to remember is that if A has to move to point B, then&lt;br /&gt;
B - A will be done, if B has to move to A,&lt;br /&gt;
then A - B will be done.&lt;br /&gt;
To make it even more useful and realistic you can include more variables like&lt;br /&gt;
FRICTION&lt;br /&gt;
ACCELERATION&lt;br /&gt;
GRAVITY,etc.&lt;br /&gt;
&lt;br /&gt;
Try this thing by actually coding it up and get first hand experience. An explaination including actual code will follow soon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/929404984894423926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/movement-formula.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/929404984894423926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/929404984894423926'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/12/movement-formula.html' title='How to move something in games c++'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9cqSVfdZDQYpfKkytsxba6VrcTx9ttjrghH6gXRhl53L-3kUV9smCkbYnHJEYeMXvO4KVm6jJc0hA0W-SYi58JlNsLz4Z5wzEgViJUSclnPsLBh6H7o_f0bPCJVAhsvlgqVE_wOzfjs0/s72-c/move.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-2025623567252379400</id><published>2011-11-29T23:56:00.001-08:00</published><updated>2012-09-12T06:04:53.254-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="2d computer games"/><category scheme="http://www.blogger.com/atom/ns#" term="2d crysis"/><category scheme="http://www.blogger.com/atom/ns#" term="2d game"/><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="computer games"/><category scheme="http://www.blogger.com/atom/ns#" term="game mechanics"/><category scheme="http://www.blogger.com/atom/ns#" term="haaf&#39;s game engine"/><category scheme="http://www.blogger.com/atom/ns#" term="hge games download"/><category scheme="http://www.blogger.com/atom/ns#" term="indiedb"/><category scheme="http://www.blogger.com/atom/ns#" term="ishkaran singh"/><category scheme="http://www.blogger.com/atom/ns#" term="shanker sharma"/><category scheme="http://www.blogger.com/atom/ns#" term="The siege"/><title type='text'>The Siege</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
My First Game using a proper 2D game engine-----&amp;gt; The Siege&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here&#39;s the download link :&lt;br /&gt;
&lt;a href=&quot;http://www.indiedb.com/members/codinpsycho/downloads/the-siege&quot;&gt;http://www.indiedb.com/members/codinpsycho/downloads/the-siege&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Developed by &lt;a href=&quot;http://www.facebook.com/pages/Game-Mechanics/163512787051561?sk=wall&quot;&gt;Game Mechanics&lt;/a&gt;&lt;br /&gt;
Members : 1. Ishkaran Singh&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2. Shanker Sharma&lt;br /&gt;
Here are some snapshots from the actual Gameplay :&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrhlidRrKsKVhAqvW55OzsWNmhE7eGMIeEvl7UxUUEmGBYEdSRWLB0biqRIpPweZ9uawYNL3xwJYGd75KBzhyBgbaXw-3F0DCsH04CYIFlffhEkqxFhUbO8q3bhjfOpb1STegP_Fq7N8/s1600/337612_198758180193688_163512787051561_441060_285607168_o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrhlidRrKsKVhAqvW55OzsWNmhE7eGMIeEvl7UxUUEmGBYEdSRWLB0biqRIpPweZ9uawYNL3xwJYGd75KBzhyBgbaXw-3F0DCsH04CYIFlffhEkqxFhUbO8q3bhjfOpb1STegP_Fq7N8/s1600/337612_198758180193688_163512787051561_441060_285607168_o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrhlidRrKsKVhAqvW55OzsWNmhE7eGMIeEvl7UxUUEmGBYEdSRWLB0biqRIpPweZ9uawYNL3xwJYGd75KBzhyBgbaXw-3F0DCsH04CYIFlffhEkqxFhUbO8q3bhjfOpb1STegP_Fq7N8/s1600/337612_198758180193688_163512787051561_441060_285607168_o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrhlidRrKsKVhAqvW55OzsWNmhE7eGMIeEvl7UxUUEmGBYEdSRWLB0biqRIpPweZ9uawYNL3xwJYGd75KBzhyBgbaXw-3F0DCsH04CYIFlffhEkqxFhUbO8q3bhjfOpb1STegP_Fq7N8/s640/337612_198758180193688_163512787051561_441060_285607168_o.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Meleeing an Enenmy down and backup coming from behind.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Near the end of first level.................see the pile of dead bodies&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx5TJAfo8KfCR0syhvuU3qNKAdP495R1NK6IxSMnzCJ6w1FayXbWf-cMveXB0orQqiYzi4Nv2oqJp-LIRGq9dZ9aWnnuG3k5SolgWc3iYshz_sdqWxCDR_cELGdWTn3FV50NxZ9P7ETZI/s1600/326200_198759576860215_163512787051561_441064_339865273_o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx5TJAfo8KfCR0syhvuU3qNKAdP495R1NK6IxSMnzCJ6w1FayXbWf-cMveXB0orQqiYzi4Nv2oqJp-LIRGq9dZ9aWnnuG3k5SolgWc3iYshz_sdqWxCDR_cELGdWTn3FV50NxZ9P7ETZI/s640/326200_198759576860215_163512787051561_441064_339865273_o.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Second Level....what the hell are those creatures.....!!&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqnTlWc9bBsaaXJ_YuCb_taDg11izIp9tYIzIIRoGqPMn4l8MQ53vPsuMV1LCH2Mp1GXMiwRY3MZPHXHI0t_lSsXYN70JxIoGzD_Jx5wO_2wseERLveYNTUtxRCxPEvuWoyanvwmwEZbY/s1600/324531_198761686860004_163512787051561_441066_748809027_o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqnTlWc9bBsaaXJ_YuCb_taDg11izIp9tYIzIIRoGqPMn4l8MQ53vPsuMV1LCH2Mp1GXMiwRY3MZPHXHI0t_lSsXYN70JxIoGzD_Jx5wO_2wseERLveYNTUtxRCxPEvuWoyanvwmwEZbY/s640/324531_198761686860004_163512787051561_441066_748809027_o.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here&#39;s some technical details :&lt;br /&gt;
&lt;br /&gt;
1.Used Visual C++ 2005&lt;br /&gt;
2.Game Engine : Haaf&#39;s Game Engine&lt;br /&gt;
3. irrKlang Sound library&lt;br /&gt;
4.Implemented State Design pattern for the architecture of the game.&lt;br /&gt;
5.Tilemaaping for placing different objects in the levels.&lt;br /&gt;
6.AI implemented through Finite State machine&lt;br /&gt;
7.Approximately more than 15000 lines of Code&lt;br /&gt;
&lt;br /&gt;
Note : 1366*768 resolution has been hard coded into it,if your monitors native resolution is not 1366*768, then please run the windowed version.&lt;br /&gt;
JUMP is through &quot;b&quot;.&lt;br /&gt;
&lt;br /&gt;
Hope you the enjoy the game and don&#39;t forget to give feedback&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/2025623567252379400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/siege.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/2025623567252379400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/2025623567252379400'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/siege.html' title='The Siege'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPrhlidRrKsKVhAqvW55OzsWNmhE7eGMIeEvl7UxUUEmGBYEdSRWLB0biqRIpPweZ9uawYNL3xwJYGd75KBzhyBgbaXw-3F0DCsH04CYIFlffhEkqxFhUbO8q3bhjfOpb1STegP_Fq7N8/s72-c/337612_198758180193688_163512787051561_441060_285607168_o.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-442858895970573263</id><published>2011-11-29T11:51:00.001-08:00</published><updated>2011-12-04T03:31:34.873-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="constant pointers"/><category scheme="http://www.blogger.com/atom/ns#" term="pointers"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="this pointer"/><title type='text'>Basics of Pointers C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;A small introduction to POINTERS.....!!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;head&gt;
&lt;meta name = &quot;keywords&quot; content = &quot;introduction pointers,basics of pointers,pointers c++,c++,programming pointers,using pointers in c++,coding everything&quot;&gt;
&lt;meta name = &quot;description&quot; content = &quot;an introductory to pointers&quot;&gt;

&lt;head/&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Pointers are generally the most feared part in a programming language. The only concept which many programmers doesnt seem to get. Well just get over the fact that pointers are somrthing terrifying build only to make prgrammers like us have horrifying nighmares....!! Heres the truth about pointers....!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;POINTERS ARE NOTHING MORE THAN A VARIABLE...!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;but the twist here is that they are a special kind of variables that stores special kind of info and that special info is the ADDRESS of another variable.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;See just like an int variable can store only int values and a float can store only float values, same is the case with the pointers. An int pointer stores the address of an integer variable only and not a float variable.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So in 1 line a pointer is :&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;SIMPLY A VRAIABLE THAT STORES ADDRESSES OF ANOTHER VARIABLE OF SAME DATA TYPE.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;DEFINING A POINTER&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;defining a pointer is a little different than defining variables.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int* x; /*we just declared an integer pointer which means that it vil only store addresses of integer variables.*/&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;dont be confused with the star (*)...u can also do lyk&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int *x or int * x...its all d same....!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Similarly to create a float or a char pointer just change the data type&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;float* x;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;char* x;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;now store something in the pointer.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;REMEMBER : The variable that the pointer is pointing to is called a &quot;POINTEE&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int pointee;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int* pointer;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;pointer = &amp;amp;pointee; //Now wat the hell is &quot;&amp;amp;&quot; for.. &amp;gt;:)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;this is known as &quot;address of&quot; operator it takes a variable and returns its address.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;for eg: &amp;amp;pointee will give you the address of pointee, remember that pointers only store addresses so if we want pointer to point to pointee we will give the address of pointee&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So pointer is pointing to pointee now so wat.....??&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Now we can access pointee through a dereference operater(*)...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int pointee = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int* pointer;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;like cout&amp;lt;&amp;lt;*pointer;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;vil give 10.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Suppose address of pointee is 1000 and value is 10.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So pointer vil store 1000 as its value and when *pointer is done, it will go to the address conatined by pointer which is 1000 as of now and vill access d value storesd at that address.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So *pointer is now the same as pointee.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;doing *pointer = 20;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;or pointee = 20 //is the same thing&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Suppose there is another int pointer&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int* another_pointer ;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;now we want this new pointer to point to the same location that pointer is pointing to.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;so we vil do lyk:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;another_pointer = pointer; //another pointer vil now also point to pointee;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So now the final programme to illustrate the concepts:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int main()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int pointee = 10;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int *pointer1, *pointer2; //u cant do lyk int* pointer1,pointer2,here pointer2 vil be pointer1 = &amp;amp;pointee; //a simple int&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;pointer1; //address of pointee&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;*pointer1; //value of pointee i.e 10&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;pointer2 = pointer1; //pointer2 now points also points to pointee&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;*pointer2 = 20; //value of pointee chngd to 20&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;pointer2; //address of pointee&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;pointer1; //same as above...address of pointee&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;*pointer2; //value of pointee which is now 20&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;*pointer1; //value os pointee which is now 20&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;I hope this vil settle all the dust about baiscs of POINTERS and now we can start understandin the intricate details about pointers and their GOTCAHS....!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;This is just a very breif intro to POINTERS and Theres still a lot to learn about pointers so keep writing code and experimenting....!!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/442858895970573263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/intro-to-pointers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/442858895970573263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/442858895970573263'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/intro-to-pointers.html' title='Basics of Pointers C++'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-3081104633205582522</id><published>2011-11-29T11:27:00.001-08:00</published><updated>2011-12-04T02:43:52.182-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="macros"/><title type='text'>Macros</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;What is a macro ?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;A macro is a piece of code that was labeled with a name. Whenever the preprocessor encounters it, the label is replaced by the associated code. Basically there are two kinds of macros : object-like macros (resemble data objects when used) and function-like macros (resemble function calls).&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Example for object-like macros:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#define HELLO &quot;Hello World Macro!&quot;&lt;br /&gt;int main(){&lt;br /&gt;printf(HELLO);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;In the above example the label is HELLO and the associated data is “Hello World Macro!“ . Before compile-time the preprocessor will replace the label with the associated code. I think the results are pretty obvious.&lt;br /&gt;&lt;br /&gt;Example for function-like macros:&lt;br /&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;#define MAX(a, b) ((a) &amp;gt; (b)) ? (a) : (b)&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;printf(&quot;%dn&quot;, MAX(1,3));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;In the case above MAX works exactly as a function that receives two arguments a, b and returns the maximum of the two . Note that the arguments are generic and appear to be typeless, the preprocessor is not performing any validation on types (that’s the compiler job) – this an advantage and also a disadvantage.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/3081104633205582522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/macros.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3081104633205582522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3081104633205582522'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/macros.html' title='Macros'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-6506308292778758674</id><published>2011-11-29T06:08:00.001-08:00</published><updated>2011-12-04T02:45:25.392-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="polymorphism"/><category scheme="http://www.blogger.com/atom/ns#" term="rules to inherit"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual functions"/><title type='text'>Inheritance + Virtual Functions = Polymorphism</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Continuing my post on INHERITANCE to INHERITANCE AND POLYMORPHISM&lt;/span&gt;&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Hope u guys hav read dat if not den plz read dat before reding dis....!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Inheritance is powerful but still u vil think dat v can do without it. Obviously yes .... v can, v have been doing without it coz v still use C language.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;But introucing d concept of POLYMORPHISM with inheritance takes d power to the next level.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;So remember INHERITANCE + POLYMORPHISM = VERY POWERFUL&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;We introduce d concept of polymorphism by introducing VIRTUAL FUNCTIONS.&lt;br /&gt;So u should first understand d concept of Virtual functions.&lt;br /&gt;For eg: We create an ENEMY class and we have 20 different types of ENEMIES&lt;br /&gt;class enemy&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;void Attack();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;So dis becomes our base class for all enemies now if we have like 20 diff. enemies in our game and all of dem have different attacks. So without using Virtual functions&lt;br /&gt;we make 20 classes for diff enemies and all of dem inherit from base class enemy.&lt;br /&gt;den enemy obj = new badEnemy();&lt;br /&gt;enemy obj1 = new BadAssEnemy();&lt;br /&gt;enemy obj2 = new RealBadAssEnemy();&lt;br /&gt;&lt;br /&gt;but when we call attack() of all three objects it will call d attack() of base class.....:( so bad na same kind of attack for every enemy makes ur game a dull game,&lt;br /&gt;UNTIL we make dat attack() function &quot;VIRTUAL&quot;. Now each enemy class vil have different implementation for their attack() which vil actually make dem different.&lt;br /&gt;like badenemy attack() simply fires a pistol at you while BadAssEnemy&#39;s attack() fires a machine gun at you and RealBadAssEnemy&#39;s attack() fires rocket launcher at u..!!&lt;br /&gt;Hope ur following d point..it gives us d power to implement d function differently for every class.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/6506308292778758674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/inheritance-virtual-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/6506308292778758674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/6506308292778758674'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/inheritance-virtual-functions.html' title='Inheritance + Virtual Functions = Polymorphism'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-3746625701123467601</id><published>2011-11-29T06:07:00.003-08:00</published><updated>2011-12-17T06:09:02.584-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="codinpsycho"/><category scheme="http://www.blogger.com/atom/ns#" term="inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="ishkaran singh"/><category scheme="http://www.blogger.com/atom/ns#" term="rule to inherit"/><title type='text'>C++ Inheritance Explained</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;INHERITANCE.....&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;inheritance is a feature which allows us to easily create new class based on already created classes. By deriving from dem and adding more functionality.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;suppose we just finished creating our class for ENEMY which takes care of enemies animations, health and ai. we use dese enemies in d whole level and wen d ending of d level comes v hav to create a boss for d level. so instead of creating a new class boss we inherit d ENEMY class and add some more functionality because even the boss vil hv animations ,health and ai. So we dnt hv to write d code again for dese thngs.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Inheritance is a very powerful tool but u shud use it wisely....&lt;br /&gt;&lt;br /&gt;Rules wether to inherit or not.&lt;br /&gt;&lt;br /&gt;Rule 1. should be &quot;Is a&quot; relationship and not &quot;Has a&quot; relationship&lt;br /&gt;derived class should follow IS A model...like BOSS is an ENEMY so it can inherit enemy class.&lt;br /&gt;&quot;has a&quot; relationship should be followed when conatinment is to be applied.&lt;br /&gt;For eg: we have a class for weapons. So should weapon class inherit enemy class?&lt;br /&gt;NO..coz a weapon is not an enemy we can also hav a weapon.&lt;br /&gt;But an ENEMY has a WEAPON so it follows HAS A relationship.&lt;br /&gt;hence enemy class vil hav an object of WEAPON class inside it as its member.&lt;br /&gt;&lt;br /&gt;Rule 2. There should be beahvioral change and not only data change&lt;br /&gt;For eg: our boss class satisfies d 1st rule but suppose our boss is dumb and acts and looks xactly d same with only difference being its health.&lt;br /&gt;suppose normal enemy int health = 100;&lt;br /&gt;Boss health = 200;&lt;br /&gt;so dere is only chnge in data bt nt in d beahvior of boss so it fails d inheritance eligibility.&lt;br /&gt;But suppose our BOSS is very powerful and can also attack us from air where as normal enemy can only attack from land. Then there is also behavioral change.Then we should inherit d enemy class.&lt;br /&gt;&lt;br /&gt;while designing architectures inheritance shud be used carefully it can either simplify ur design or make ur nights sleepless.&lt;br /&gt;These are d 2 thumb rules that u shud always consider while deciding wether to inherit or not.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/3746625701123467601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/some-insight-into-inheritance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3746625701123467601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3746625701123467601'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/some-insight-into-inheritance.html' title='C++ Inheritance Explained'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-3376666054357505644</id><published>2011-11-29T06:07:00.001-08:00</published><updated>2011-12-04T00:23:14.462-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="stdarg.h"/><category scheme="http://www.blogger.com/atom/ns#" term="variable argument functions"/><title type='text'>Variadic Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;‎#include&amp;lt;stdarg.h&amp;gt; is a header file which enables us to pass multiple arguments to a function.You can pass multiple arguments by using &quot;...&quot; after d last variable.&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://codinpsycho.blogspot.com/2011/11/variadic-functions.html&quot;&gt;&lt;/a&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;for eg: avg(int num,...);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;so this function avg(int num,...) vil take variable no of arguments and 1 integer arguments for num.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;it has 1 type : va_list to hold info abt variable arguments&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;and 3 functions&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;1. va_start&lt;br /&gt;2. va_arg&lt;br /&gt;3. va_end&lt;br /&gt;&lt;br /&gt;va_start is used to start iterating by passing it 2 arguments : an object of type va_list&lt;br /&gt;and second parameter is d last named parameter of d function&lt;br /&gt;&lt;br /&gt;for eg: avg(int num,...)&lt;br /&gt;den va_list l;&lt;br /&gt;va_start(l,num); //dis initializes d list of variable arguments&lt;br /&gt;&lt;br /&gt;now to use individual arguments we use va_arg()&lt;br /&gt;it accepts va_list as first argument and type of d argument in the list.&lt;br /&gt;i.e va_arg(l,int); it returns d arguments in d same order in which dey were passed to the function...!!&lt;br /&gt;&lt;br /&gt;when we r done we use va_end to free d memory used by our list.&lt;br /&gt;In c it is mandatory to give 1 normal parameter but in c++ its nt mandatory....!!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/3376666054357505644/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/variadic-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3376666054357505644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3376666054357505644'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/variadic-functions.html' title='Variadic Functions'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-3044590361174241339</id><published>2011-11-29T06:05:00.001-08:00</published><updated>2011-12-04T00:25:19.421-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="virtual functions"/><category scheme="http://www.blogger.com/atom/ns#" term="vptr"/><category scheme="http://www.blogger.com/atom/ns#" term="vtable"/><category scheme="http://www.blogger.com/atom/ns#" term="working of virtual functions"/><title type='text'>Basics of Virtual Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;WORKING OF VIRTUAL FUNCTIONS&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://codinpsycho.blogspot.com/2011/11/variadic-functions.html&quot;&gt;&lt;/a&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;The address of all the functions are known at compile time with the exception of virtual functions. There address is not known at until run time, this is an example of late binding.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;One of d factors deciding the size of an executable (.exe) depends on this binding if a lot of early binding is done d size tends to increase and with late binding the size tends to decrease.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;In the world of VIRTUAL functions there are &quot;VTABLES&quot; and &quot;VPTRS&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;VTABLES: They are an array of function pointers which holds the addresses of all the virtual functions.&lt;br /&gt;Only 1 VTABLE is generated for a single class&lt;br /&gt;VPTRS: It is a pointer which points at a location inside the VTABLE.Each object will have a VPTR which points to the correct location in a VTABLE.&lt;br /&gt;&lt;br /&gt;SO what happens when we call a virtual function&lt;br /&gt;&lt;br /&gt;1&lt;i&gt;.&lt;b&gt;VPTR&lt;/b&gt; of that object is fetched&lt;/i&gt;&lt;br /&gt;2.&lt;i&gt;Offset in the &lt;b&gt;VTABLE&lt;/b&gt; is calculated&lt;/i&gt;&lt;br /&gt;3. At that offset is d function pointer which is pointing to the virtual function which is then fetched&lt;br /&gt;4. finally the function call is made.&lt;br /&gt;&lt;br /&gt;Though the actual memory footprint of a virtual function is very complex but dis is d crux of what happens behind and should give u a basic understanding.&lt;br /&gt;&lt;br /&gt;NOTE: Compilers are smart enough to optimize VIRTUAL function calls.&lt;br /&gt;For eg:&lt;br /&gt;&lt;b&gt;class A&lt;br /&gt;{&lt;br /&gt;virtual void func();&lt;br /&gt;}&lt;br /&gt;class B : public A&lt;br /&gt;{&lt;br /&gt;virtual void func();&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;A* obj = new B():&lt;br /&gt;B* obj1 = new B():&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;obj.func(); \\Virtual function overhead, VTABLE lookup occurs here&lt;br /&gt;obj1.func(); \\No overhead here simple member function call passing a &quot;this&quot; pointer.&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/3044590361174241339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/basics-of-virtual-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3044590361174241339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/3044590361174241339'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/basics-of-virtual-functions.html' title='Basics of Virtual Functions'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-8987312981322461337</id><published>2011-11-29T06:04:00.001-08:00</published><updated>2011-12-04T02:46:55.380-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="hidden this pointer in member functions"/><category scheme="http://www.blogger.com/atom/ns#" term="implicit passing this pointer"/><category scheme="http://www.blogger.com/atom/ns#" term="this pointer"/><title type='text'>Hidden parameter : this Pointer to member function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-size: 11px; line-height: 14px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif;&quot;&gt;&lt;b&gt;&lt;u&gt;Implicit this pointer&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Whenever we create a class&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;There are data members and member functions...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;for eg:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;class A&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int x;&lt;br /&gt;public:&lt;br /&gt;void display();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;A obj,obj1,obj2;&lt;br /&gt;&lt;br /&gt;Now each obj,obj1 and obj2 vil have there own local copy of x.&lt;br /&gt;But there vil be only 1 copy of Display() in memory not THREE copies.&lt;br /&gt;So how does the Display() know which objects&#39;x X to show....??&lt;br /&gt;&lt;br /&gt;This is solved by the compiler by implicitly passing a &quot;this&quot; pointer to display function.&lt;br /&gt;Read the next line carefully&lt;br /&gt;&quot;A this pointer is a pointer which points to the calling object.&quot;&lt;br /&gt;so obj.display();&lt;br /&gt;In this case it vil be of type A and it vil point to address of obj.&lt;br /&gt;so this call obj.display() will internally become A_display(&amp;amp;obj).&lt;br /&gt;So &amp;amp;obj gives display() function the address of the calling object i.e this pointe.So it knows which object to access.&lt;br /&gt;And REMEMBER this pointer is passed implicitly by the compiler i.e without the knowledge of the programmer.&lt;br /&gt;But now u knw...lol&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/8987312981322461337/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/implicit-this-pointer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/8987312981322461337'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/8987312981322461337'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/implicit-this-pointer.html' title='Hidden parameter : this Pointer to member function'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-4937157421689011663</id><published>2011-11-29T06:02:00.001-08:00</published><updated>2011-12-04T02:47:07.809-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="class padding"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="padding in c"/><category scheme="http://www.blogger.com/atom/ns#" term="size of a class/structure"/><category scheme="http://www.blogger.com/atom/ns#" term="stucture padding"/><title type='text'>Structure/Class Padding</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;b&gt;Structure Padding:&lt;/b&gt;&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Whenever we create classes and structures we should pay special attention to the way we r defining variables insdie, because the size of the struct or class depends on it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Also frequently used variables shoild be kept on top in order to avoid cache misses.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;A class or a struct is always a multiple of the largest sized datatype inside it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;for eg:&lt;br /&gt;&lt;b&gt;struct A&lt;br /&gt;{&lt;br /&gt;double a;&lt;br /&gt;char ch;&lt;br /&gt;};&lt;/b&gt;&lt;br /&gt;now sizeof(A) == 16 and not 8 + 1 = 9&lt;br /&gt;even if the struct is rewritten like&lt;br /&gt;&lt;b&gt;struct A&lt;br /&gt;{&lt;br /&gt;double a;&lt;br /&gt;char ch;&lt;br /&gt;char ch1;&lt;br /&gt;char ch2;&lt;br /&gt;char ch3;&lt;br /&gt;};&lt;/b&gt;&lt;br /&gt;even then the size vil be 16&lt;br /&gt;&lt;br /&gt;All variables defined inside a struct or a class are alligned in memory according to their size. Like an int can only be stored at addresses 4,8 and 12 that are multiples of 4.&lt;br /&gt;6 is an invalid address for an int.Similarly for double it can be strored only at multiples of 8.&lt;br /&gt;NOTE: A char can be stored at any byte coz its nly of 1 byte.&lt;br /&gt;for eg:&lt;br /&gt;&lt;b&gt;struct A&lt;br /&gt;{&lt;br /&gt;char ch;&lt;br /&gt;int x;&lt;br /&gt;char ch1;&lt;br /&gt;double d;&lt;br /&gt;};&lt;/b&gt;&lt;br /&gt;1 + 4 + 1 + 8 = 14 and considering double&lt;br /&gt;final size must be 16 but actually&lt;br /&gt;&lt;br /&gt;sizeof(A) == 24 .............WHY???&lt;br /&gt;&lt;br /&gt;Now lets see WHY, hypothetical starting address 0;&lt;br /&gt;0-1 1 byte for ch&lt;br /&gt;now next valid address for int is 4, hence&lt;br /&gt;1-2 padding&lt;br /&gt;2-3 padding&lt;br /&gt;3-4 padding&lt;br /&gt;4-8 4 bytes for int&lt;br /&gt;8-9 1 byte for ch1&lt;br /&gt;Now next valid address for double vil be 16, hence&lt;br /&gt;9-16 7 bytes for padding&lt;br /&gt;16-24 8 bytes for d&lt;br /&gt;&lt;br /&gt;So we wasted 10 bytes in padding dats actually a quite if you use dis struct for creating a 2D array of size 100*100&lt;br /&gt;total objects of struct = 10000&lt;br /&gt;bytes wasted on padding = 10000* 10 bytes&lt;br /&gt;Approx 98 kB is being wasted on just padding.&lt;br /&gt;Lets rearrange d structrure now&lt;br /&gt;&lt;b&gt;struct A&lt;br /&gt;{&lt;br /&gt;double d;&lt;br /&gt;int x;&lt;br /&gt;char ch;&lt;br /&gt;char ch1;&lt;br /&gt;};&lt;/b&gt;&lt;br /&gt;0-8 8 bytes for double&lt;br /&gt;8-12 4 bytes for int&lt;br /&gt;12-13 1 byte for ch&lt;br /&gt;13-14 1 byte for ch1&lt;br /&gt;since d structure needs to be a multiple of 8 so final size would be 16&lt;br /&gt;Only 2 bytes required for padding&lt;br /&gt;So for 100*100 array only 19kB is wasted on padding&lt;br /&gt;Simply shuffling d variables inside saved us 78kB&lt;br /&gt;So always keep this thing in mind while creating classes and structure in the future.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/4937157421689011663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/structureclass-padding.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4937157421689011663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4937157421689011663'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/structureclass-padding.html' title='Structure/Class Padding'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-8188722781216514660</id><published>2011-11-29T06:01:00.001-08:00</published><updated>2011-12-04T02:47:24.745-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="different ways to use static"/><category scheme="http://www.blogger.com/atom/ns#" term="static functions"/><category scheme="http://www.blogger.com/atom/ns#" term="static keyword"/><category scheme="http://www.blogger.com/atom/ns#" term="static variables"/><title type='text'>Two faces of STATIC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;By default all functions are implicitly declared as extern, which means they&#39;re visible across translation units. But when we use static it restricts visibility of the function to the translation unit in which it&#39;s defined. So we can say&lt;/span&gt;&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Functions that are visible only to other functions in the same file are known as static functions.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Let use try out some code about static functions.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;main.c&lt;br /&gt;&lt;br /&gt;&lt;b&gt;#include &quot;header.h&quot;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;hello();&lt;br /&gt;return 0;&lt;br /&gt;}&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;func.c&lt;br /&gt;&lt;br /&gt;&lt;b&gt;#include &quot;header.h&quot;&lt;br /&gt;&lt;br /&gt;void int hello()&lt;br /&gt;{&lt;br /&gt;printf(&quot;HELLO WORLD\n&quot;);&lt;br /&gt;}&amp;nbsp;&lt;/b&gt;&lt;br /&gt;header.h&lt;br /&gt;view plainprint?&lt;br /&gt;&lt;b&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;static int hello();&amp;nbsp;&lt;/b&gt;If we compile above code it fails as shown below&lt;br /&gt;view plainprint?&lt;br /&gt;$gcc main.c func.c&lt;br /&gt;header.h:4: warning: &quot;hello&quot; used but never defined&lt;br /&gt;/tmp/ccaHx5Ic.o: In function `main&#39;:&lt;br /&gt;main.c:(.text+0x12): undefined reference to `hello&#39;&lt;br /&gt;collect2: ld returned 1 exit status&lt;br /&gt;It fails in Linking since function hello() is declared as static and its definition is accessible only within func.c file but not for main.c file. All the functions within func.c can access hello() function but not by functions outside func.c file.&lt;br /&gt;&lt;br /&gt;Using this concept we can restrict others from accessing the internal functions which we want to hide from outside world. Now we don&#39;t need to create private header files for internal functions.&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;For some reason, static has different meanings in in different contexts.&lt;br /&gt;&lt;br /&gt;1. When specified on a function declaration, it makes the function local to the file.&lt;br /&gt;2. When specified with a variable inside a function, it allows the variable to retain its value between calls to the function. See static variables.&lt;br /&gt;&lt;br /&gt;It seems a little strange that the same keyword has such different meanings...&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/8188722781216514660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/two-faces-of-static.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/8188722781216514660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/8188722781216514660'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/two-faces-of-static.html' title='Two faces of STATIC'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-4849751783801962268</id><published>2011-11-29T06:00:00.001-08:00</published><updated>2011-12-04T02:48:48.219-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="passing by value"/><category scheme="http://www.blogger.com/atom/ns#" term="return by value"/><category scheme="http://www.blogger.com/atom/ns#" term="temporaries c++"/><category scheme="http://www.blogger.com/atom/ns#" term="type mismatch"/><category scheme="http://www.blogger.com/atom/ns#" term="understanding temporaries"/><category scheme="http://www.blogger.com/atom/ns#" term="when temporaries are generated"/><title type='text'>How and When are Temporaries generated</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;Understanding Temporaries&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Temporaries are 1 of the main bottlenecks in creating high speed and efficient software.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;so their understanding is very important.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;A temporary as the name suggests is a hidden object that the compiler creates itself in order to achive something.Its done implicitly by the compiler without the knowledge of the programmer.&lt;br /&gt;Main reasons for compilers such behavior is&lt;br /&gt;1.&lt;i&gt;TYPE MISMATCH&lt;/i&gt;&lt;br /&gt;2.&lt;i&gt;PASSING BY VALUE&lt;/i&gt;&lt;br /&gt;3.&lt;i&gt;RETURNING BY VALUE&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;1.Type mismatch&lt;br /&gt;for eg:&lt;br /&gt;&lt;b&gt;class A&lt;br /&gt;{&lt;br /&gt;int var;&lt;br /&gt;public:&lt;br /&gt;A(int x)&lt;br /&gt;{&lt;br /&gt;var = x;&lt;br /&gt;}&lt;br /&gt;void func(A);&lt;br /&gt;};&lt;/b&gt;&lt;br /&gt;Now here is a constructor for A which takes an integer argument...!!&lt;br /&gt;So now dese r d ways in which we can create objects for A&lt;br /&gt;A a(10); \\Normal nthng unusual&lt;br /&gt;A a = 10; \\Hey wats happening here&lt;br /&gt;a.func(10); \\Hey wats happening here&lt;br /&gt;So wats happening in these two lines...??&lt;br /&gt;actually the compiler was expecting an object of A as function argument and on RHS..&lt;br /&gt;but instead it got an &quot;int&quot;....But wait these lines still runs and the compiler doesnt complain. This shows that compiler is very generous and is helping us underneath.&lt;br /&gt;Actually the compiler knows that an object of can be created if it has an integer argument, SO&lt;br /&gt;it creates a TEMPORARY.....!!&lt;br /&gt;A temp(10); //Constructor called&lt;br /&gt;a = temp; //Copy constructor called&lt;br /&gt;~temp; //Destructor called&lt;br /&gt;So u see just to create a TEMPORARY&lt;br /&gt;2 constructors and 1 destructor is called...u will say so what&lt;br /&gt;when we do&lt;br /&gt;int = int + int...no 1 complained for this so far&lt;br /&gt;but listen guys temporaries are not significant for primitive data types but for user defined object of size 100 bytes IT IS SIGNIFICANT.&lt;br /&gt;So A = A + A; vil also create a temporary if &#39;+&#39; operator is overloaded.&lt;br /&gt;a way to overcome dis is use += unary operator.&lt;br /&gt;A obj,obj1,obj2;&lt;br /&gt;for obj = obj1 + obj2; \\Temporary here&lt;br /&gt;but obj = obj1 \\No Temporary&lt;br /&gt;obj += obj2 \\No Temporary here as well&lt;br /&gt;&lt;br /&gt;Also Remember passing by value and returning by value also creates a TEMPOARAY. As a local copy is always created.&lt;br /&gt;So always try to pass pointers or better References.&lt;br /&gt;&lt;br /&gt;And these constructors are called &quot;Converting Constructors&quot;&lt;br /&gt;To prevent this we should use &quot;Explicit constructors&quot;&lt;br /&gt;explicit A(int)&lt;br /&gt;now it wont create a temporary :)&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/4849751783801962268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/understanding-temporaries.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4849751783801962268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4849751783801962268'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/understanding-temporaries.html' title='How and When are Temporaries generated'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-2826496797981265294</id><published>2011-11-29T05:55:00.001-08:00</published><updated>2011-12-04T02:49:01.253-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="file handling c++"/><category scheme="http://www.blogger.com/atom/ns#" term="ifstream"/><category scheme="http://www.blogger.com/atom/ns#" term="ofstream"/><category scheme="http://www.blogger.com/atom/ns#" term="reading a file c++"/><category scheme="http://www.blogger.com/atom/ns#" term="writing a file c++"/><title type='text'>File Handling in C++(Basics)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;File Handling in C++(Basics)&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;File handling is done so dat u can store any result or output to your Hard disk and read dat later on.For eg:&lt;/span&gt;&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;you write a programme to accept the marks of students of your class and store dem in some variables.But as soon d programme is over all those variables are erased from the memory thus all your data is gone.Hence you need to store them in some file from where u can read dem later.This is achieved by &lt;i&gt;FILE HANDLING&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;First of all u need &quot;fstream&quot; header file.So include it&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;after dat u need to open a file either in READ(ifstream) mode or in WRITE(ofstream) mode or in READ-WRITE(fstream) mode.For eg:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;ifstream read;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;read.open(&quot;filename&quot;,mode);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;There are different modes in which you can open files.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Deafult modes&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Ifstream ios::in&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;ofstream ios::out&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;fstream ios::in | ios::out&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;All modes&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::app&lt;/b&gt; If FileName is a new file, data is written to it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;If FileName already exists and contains data, then it is opened, the compiler&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;goes to the end of the file and adds the new data to it.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::ate&lt;/b&gt; If FileName is a new file, data is written to it and subsequently added to the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;end of the file. If FileName already exists and contains data, then it is opened and data is&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;written in the current position.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::in&lt;/b&gt; If FileName is a new file, then it gets created fine as an empty file.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;If FileName already exists, then it is opened and its content is made available&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;for processing.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::out&lt;/b&gt; If FileName is a new file, then it gets created fine as an empty file. Once/Since it gets created empty, you can write data to it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;If FileName already exists, then it is opened, its content is destroyed, and the file becomes as new.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Therefore you can create new data to write to it. Then,if you save the file, which is the main purpose of this mode, the new content&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;is saved it.This operation is typically used when you want to save a file&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::trunc&lt;/b&gt; If FileName already exists, its content is destroyed and the file becomes as new.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::nocreate&lt;/b&gt; If FileName is a new file, the operation fails because it cannot create a new file.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;If FileName already exists, then it is opened and its content is made available for processing.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ios::noreplace&lt;/b&gt; If FileName is a new file, then it gets created fine.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;If FileName already exists and you try to open it, this operation would fail because it cannot create a file of the same name in the same location.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;//////////////WRITING/////////&lt;/span&gt;&lt;wbr style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/wbr&gt;&lt;span class=&quot;word_break&quot; style=&quot;background-color: white; display: inline-block; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;//////&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Now lets try to open a file, write to it, and save it to hard disk&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;#include&amp;lt;fstream&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;#include&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int main()&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;ofstream write_file(&quot;c:/&lt;/span&gt;&lt;wbr style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/wbr&gt;&lt;span class=&quot;word_break&quot; style=&quot;background-color: white; display: inline-block; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;ishkaran.txt&quot;); //file opened in write mode&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;write_file &amp;lt;&amp;lt; &quot;hello!&quot;;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;write_file.close(); //file closed&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;return 0;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;It will create a txt file in your c:\ drive of name ishkaran.txt then it vil write to dat file the string provided and den it vil close d file.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;You can also check if the file has been properly opened before readin or writing to it by&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;if(write_file.is_open())&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;//Do something with the file&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;///////////////READING////////&lt;/span&gt;&lt;wbr style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/wbr&gt;&lt;span class=&quot;word_break&quot; style=&quot;background-color: white; display: inline-block; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;/////////////&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Now lets read the file we just wrote to.&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int main()&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;{char ch[256];&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;ifstream read_file(&quot;c:/ishkaran.txt&quot;); //file opened in write mode&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;read_file &amp;gt;&amp;gt; ch;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;cout&amp;lt;&amp;lt;ch;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;read_file.close(); //file closed&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;return 0;&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;this will print hello but deres a problem here it will read until a space is encountered. So to overcome that uoy should use&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;read_file.getline( char*,int count,char delimiter);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;it reads the number of characters specified in count and passes it to 1st argument either this or it will read until delimiter character is encountered whichever happems first.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;u can read like this&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;while(!read_file.eof())&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;//Read here&lt;/span&gt;&lt;br style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot; /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;}&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;this loop will work until whole of the file is read. &lt;i&gt;&lt;u&gt;eof()&lt;/u&gt;&lt;/i&gt; returns true if End of File is encountered.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;I have explained only the basics, reading and writing simple data types&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Theres still a lot more to file handling ....Will explain more in further posts....!!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/2826496797981265294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/file-handling-in-cbasics.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/2826496797981265294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/2826496797981265294'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/file-handling-in-cbasics.html' title='File Handling in C++(Basics)'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-4431145152095674115</id><published>2011-11-29T05:52:00.001-08:00</published><updated>2011-12-04T02:49:20.385-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="constant pointers"/><category scheme="http://www.blogger.com/atom/ns#" term="how arrays work"/><category scheme="http://www.blogger.com/atom/ns#" term="what are arrays"/><title type='text'>ARRAYS----&gt;</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;&lt;b&gt;ARRAYS----&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;From bookish point of view...an array is a collection of homogeneous data, by homogeneous we mean dat the data vil be of same data type,may it be int or char or float.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;int arr[10]..is an array of data type integer with 10 variables occupying size of 40 bytes.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Dis vil be same as defining int a0,a1,a.....a9&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;But the difference is dat v can now access dem easily through 1 name.&lt;br /&gt;for eg: if v want to access 2nd element we will do like arr[1] ,5th element arr[4] and so on.&lt;br /&gt;Remember: array-name[index]&lt;br /&gt;array-name can be anythng and index starts from 0 and not 1.&lt;br /&gt;an array of 5 elements: &lt;b&gt;int arr[5]&lt;/b&gt;&lt;br /&gt;defining simple variables : arr1 arr2 arr3 arr4 arr5&lt;br /&gt;using array arr[0] arr[1] arr[2] arr[3] arr[4]&lt;br /&gt;notice the indices&lt;br /&gt;Hope u get it..!!&lt;br /&gt;You can treat them just like normal variables but accessing them through array style.&lt;br /&gt;Remember: Arrays are allocated in memory contiguously.&lt;br /&gt;for eg: in ram arr[0],arr[1],arr[2] will be adjuacent to each other&lt;br /&gt;like address of arr[0] is 1000,address[1] is 1004 and so on...!!&lt;br /&gt;Now internally arrays are nothing more than &lt;b&gt;&lt;i&gt;&lt;u&gt;&quot;CONSTANT POINTERS&lt;/u&gt;&lt;/i&gt;&quot;&lt;/b&gt;.&lt;br /&gt;For eg: u declare int arr[10];&lt;br /&gt;then arr is only the address of arr[0] and it vil always point to that location only&lt;br /&gt;For eg : int arr[5]; lets assume arr is pointing to 1000&lt;br /&gt;So what happens when u require arr[3].&lt;br /&gt;&lt;b&gt;arr + index*sizeof(datatype)&lt;/b&gt; this formula is used&lt;br /&gt;&lt;b&gt;1000 + 3*4 //sizeof(int)&lt;/b&gt; is 4&lt;br /&gt;which gives 1012 this vil be the address of arr[3].&lt;br /&gt;Remember when i told u that arrays are allocated contigously in memory.This is the main importance . if they are not allocated contiguously then this scheme would fail.&lt;br /&gt;Since the compiler just multiplies d index with the size of data type and adds it to base address...u vil be surprised to knw that u can also use array like&lt;br /&gt;3[arr]..this vil be same as arr[3].&lt;br /&gt;&lt;br /&gt;and remember that arrays are like constant pointers internally&lt;br /&gt;you cannot assign an array to another variable once its been defined.&lt;br /&gt;and due to the way that arrays are implemented internally they hav O(c) access time..&lt;br /&gt;which means constant access time.&lt;br /&gt;for further experience actually code the arrays for first hand experience.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/4431145152095674115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/arrays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4431145152095674115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/4431145152095674115'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/arrays.html' title='ARRAYS----&gt;'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5552992012603264667.post-5184263609291529075</id><published>2011-11-29T05:50:00.001-08:00</published><updated>2011-12-04T00:27:27.330-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="argc"/><category scheme="http://www.blogger.com/atom/ns#" term="argv"/><category scheme="http://www.blogger.com/atom/ns#" term="coding everything"/><category scheme="http://www.blogger.com/atom/ns#" term="how main works"/><category scheme="http://www.blogger.com/atom/ns#" term="main()"/><category scheme="http://www.blogger.com/atom/ns#" term="passing arguments to main()"/><title type='text'>Few things about MAIN() ( C/C++)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;Few things about MAIN()&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://codinpsycho.blogspot.com/2011/11/few-things-about-main-cc.html&quot;&gt;&lt;/a&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;We all are aware of tis function,right? We all love this function coz its the entry point of our software.Actually before main() is entered preprocessor is run which processes everything defined/declared before entering main(),for eg: including header files,processing macros, etc.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;By ISO standard main() should always return int.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;You should always declare int main(), you can also use void but remember the standard is using &quot;int main()&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;text_exposed_show&quot; style=&quot;background-color: white; display: inline; font-family: &#39;lucida grande&#39;, tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;&quot;&gt;It should return 0 on successful completion and 1 on unsuccessful completion.&lt;br /&gt;Remember you can also return any other value like return 10, return 23 anything but remeber what the standard is.&lt;br /&gt;&lt;br /&gt;Passing Arguments to main()----&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;int main( int argc, char* argv[] )&lt;/b&gt;&lt;br /&gt;this is the syntax for main(),expecting 2 arguments ARGC( ARGUMENT COUNT ) of type int and ARGV( ARGUMENT VECTOR ) of type char**.It can also be denoted as char*[].It means that it points to an array of char*.You can also declare like&lt;br /&gt;int main( int argc, char** argv )&lt;br /&gt;There are at least two arguments to main: argc and argv. The first of these is a count of the arguments supplied to the program and the second is an array of pointers to the strings which are those arguments—its type is (almost) ‘array of pointer to char’.&lt;br /&gt;Now u run the programme and say &quot;hey, Wait id dint paased any arguments&quot;&lt;br /&gt;REMEMBER: that u pass arguments through command line i.e dos in other wrds command prompt(CMD).For any1 who hasnt seen cmd type cmd in run(win + r).&lt;br /&gt;&lt;br /&gt;When a program starts, the arguments to main will have been initialized to meet the following conditions:&lt;br /&gt;1. argc is greater than zero.&lt;br /&gt;2. argv[argc] is a null pointer.&lt;br /&gt;3. argv[0] will be a string containing the program&#39;s name or a null string if that is not available. Remaining elements of argv represent the arguments supplied to the program. In cases where there is only support for single-case characters, the contents of these strings will be supplied to the program in lower-case.&lt;br /&gt;Now wat u actually do with these arguments inside your programme depends on you.&lt;br /&gt;The most imp thing to remember is that :&lt;br /&gt;ARGC(ARGUMENT COUNT) tells us how many arguments are passed to your programme which are stored in ARGV( ARGUMENT VECTOR ).&lt;br /&gt;Default value of ARGC is 1 because the first argument inside ARGV is the path of the exe file itself(m talkng abt windows, dnt knw bt linux :( ).&lt;br /&gt;&lt;br /&gt;A sample programme:&lt;br /&gt;&lt;b&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char **argv)&lt;br /&gt;{&lt;br /&gt;while(argc--)&lt;br /&gt;printf(&quot;%s\n&quot;, *argv++);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;But on visual studio 2005 the implementation is a little diff.&lt;br /&gt;for eg: if you pass 2 arguments to the programme,then argv[2] will be the name of the programme and not argv[0].&lt;br /&gt;rest is same.&lt;br /&gt;Write code to actually get the first hand experience.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codinpsycho.blogspot.com/feeds/5184263609291529075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/few-things-about-main-cc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/5184263609291529075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5552992012603264667/posts/default/5184263609291529075'/><link rel='alternate' type='text/html' href='http://codinpsycho.blogspot.com/2011/11/few-things-about-main-cc.html' title='Few things about MAIN() ( C/C++)'/><author><name>Ishkaran Singh</name><uri>http://www.blogger.com/profile/15940790056395530310</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQj7hfVVO8c0wgF7pCw28opxphD0XMHeCYpPi_cdVeeSuBOy6ytcxJk1U-97jGVOs2AV6dv-Jhzc8RiwIKGtKC01ODRIevlLWKtC84kxZ7VwGEC2vyv5gmvz0daBFERw/s220/ish.jpg'/></author><thr:total>0</thr:total></entry></feed>