Virtual Functions in C++

 Virtual functions, a very common topic when we talk about classes and inheritance topics in C++, this mainly comes into use when suppose we are using a base class pointer to access methods of derived class. 

What are Virtual Functions exactly?

So, the answer can be that they are simply member functions that are declared in the base class using the keyword "virtual" and they are overriden by the derived class. When we call a method of a derived class using a pointer of base class(provided the functions have the same name, and the pointer is being pointed to the object of derived class), ideally the function of derived class should be called but instead what happens is that the function of base class is called and basically to resolve this anomaly we use the virtual functions. It is always a good practice to make every function virtual. In fact they are so important that in Java language every member function if virtual by default.

So, we can understand the importance of virtual functions by this. 

 Most of the part of C++ is easy. I am just confused about how to balance all these languages altogether, it becomes very confusing when dealing with 3 to 4 languages like C++, python, JS, and C. That is why I have decided that in one time I will be focussing on any one language only, for a sufficient amount of time, actually I got this idea from my friends. But that was in some other context, but still I, I always try to go overboard, and see if the plan holds water.

Well enough for today, it was a good day, did almost 6 problems on hackerrank and my typing speed is now averaging 50, the book I am currently reading will be over in about 4 to 5 days, I just realised that then I have to write a book review on it too, well it will be interesting to do that.

Peace Out!

Ger Outta Here!

Comments

Popular Posts