Thursday 31 December 2015

2015, a memory

When one chapter ends, other begins. Sometimes ending hearts but beginning of other worth the pain. Here it comes the last day of 2015, time to say good bye to the another chapter of life. After all the year was full of memories.
Dear 2015 it was nice to spent time with you, you brought a lot changes in life personally and professionally. You added another lesson how to stand firm in adverse circumstances and grew up an attitude of never giveing up. The best from you was to bringing up some amazing people in my life.
Here is the list of the idiots who amazes every time when they are around.




Akshay and Akshya the two brilliant geeks, one is Peter Baelish(right one) of our group who knows every technical aspect without him we could be losing the real test of roaming and learning. And the other one is Lord Varys(left one). No one can beat him if it come to witty comebacks and entertaining people.  This duo is never separable. A great helping hand personally and professionally.



A pro bro,the Jorah Mormont of the group, who speaks very less but when speaks only about pro things. The man who made Uber a Knagal (:P). A passionate traveler, eater and many more. A great skill of restaurant selection. No matter how much debt he has, never stops himself from buying a new gadget.


The mother of the dragons(group members), our Khalisi. The die hard caring lady.If you start late for home she will call you 10 times to make sure you reach home safely. She has restriction, can't survive outside after 10 PM (:P). A lady who will beat you out of hell if you make mistake in front of her.
A great friend who shares almost everything and you  have to  listen her, you have no option (:P).






The Brienne of Tarth, one of the strongest ladies I have met, deals with situation firmly. Full of fantasies. Travels miles to balance her professional and personal life. A great inspiration for those who easily give up. Learn't many things from you my lady.




The Queen Margery, a cute, charming, angelic, stunning, magnificent lady. Attracts people's attention when stands with. An professional beater, expert pincher. A born hungry, who wants to eat such a thing which she herself can't explain. A silent observer who notices each and everything around.

Thank you 2015 to bring in such a amazing people in my life. These are the people who makes my life easy when it seems difficult.
With the hope of amazing journey ahead, signing off..
Bbye 2015.

Saturday 19 December 2015

About Me


Name : Sarfraz, most of my colleagues call me surf or some times surf-excel (Daag Achhe Hain).
Born and brought up in India, a country full of beauty and diversity, love my country more than any thing.
A Software Engineer,a die-hard coder, an avid writer, a passionate shayar, a photographer, a Romyo in search of Juliet.
Take time to gel-up, once gelled up, you will have best of me.
Love to help needy people, spending time with street/slum children. Have very sensitive heart inside which melts down easily.
A good friend who always stands together in all circumstances.
A sarcastic kid sometimes who will drive you crazy.
One who loves Family, Friends and neighbor (:P).

    Want to know more, come and meet me dude :D.

Understanding virtual function in CPP

A function declared with keyword virtual is called virtual function. Virtual functions are handy when classes are Polymorphic i.e when child class and parent classes have functions with same name.
Let's understand the problem when we don't use virtual function.

#include<iostream>
using namespace std;
class Parent{
public:
void showMe(){
cout<<"\nParent is showing!";
}
};

class Child: public Parent{
public:
void showMe(){
cout<<"\nChild is showing!";
}
};

int main(){
Parent *parentPointer;
parentPointer = new Parent();
parentPointer->showMe();//its calling Parent->showMe()//

parentPointer = new Child();
parentPointer->showMe(); //it is also calling Parent->showMe()//
return 0;
}

Output:
Parent is showing!
Parent is showing!

When we don't declare Parent class function as a virtual, compiler does early binding which means for all the direct function references compiler will replace the reference with actual address of the method.
Now let's declare the Parent class function as a virtual

#include<iostream>
using namespace std;
class Parent{
public:
virtual void showMe(){
cout<<"\nParent is showing!";
}
};

class Child: public Parent{
public:
void showMe(){
cout<<"\nChild is showing!";
}
};

int main(){
Parent *parentPointer;
parentPointer = new Parent();
parentPointer->showMe();//it is calling Parent->showMe()//

parentPointer = new Child();
parentPointer->showMe(); //Now it is calling Child->showMe()//
return 0;
}

Output:
Parent is showing!
Child is showing!

When we declare the base class function as virtual, the function call using a Parent reference, as in shown in second example, compiler does not know which method will get called at run time. In this case compiler will replace the reference with code to get the address of function at run-time.

Why do we need to use Parent class pointer, cant we just declare Child class pointer itself and call the respective function instead declaring  virtual function?

Valid question, but consider a scenario when we have a Parent class Animal and Children classes Dog, Cat, Rat, Fox etc, each one has one common function says():
Now we have a function which demonstrates how individual animal sounds which will accept Parent class point because it has to access each of it's child class function;

void animalSound(Animal *pointer){
    pointer->says();
}

If we want animalSound function to call the child class function, we need delay the binding of early binding by declaring Animal class says() function as virtual.