We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Actually you can define virtual functions besides just to declaring them. There is a distinction whether the virtual function is just virtual or is it also pure virtual. In most languages latter is called abstract. There is no keyword abstract in C++ but abstract functions are marked with = 0 ending like so:
In madhurachanna23 post, it has been decided to opt for just virtual, but not for pure virtual functions. The difference now is that if one has object of Person (not the derived one) the Person's functions are to be used. But for derived classes the overrided versions are called. In our case Professor object uses it's own functions and so does Student.
If you opt for pure virtual functions then you have to note, that this makes the class itself abstract, too, and you cannot make objects that are purely Persons (in our case), only sub-classes of it.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Virtual Functions
You are viewing a single comment's thread. Return to all comments →
Actually you can define virtual functions besides just to declaring them. There is a distinction whether the virtual function is just virtual or is it also pure virtual. In most languages latter is called abstract. There is no keyword abstract in C++ but abstract functions are marked with = 0 ending like so:
In madhurachanna23 post, it has been decided to opt for just virtual, but not for pure virtual functions. The difference now is that if one has object of Person (not the derived one) the Person's functions are to be used. But for derived classes the overrided versions are called. In our case Professor object uses it's own functions and so does Student.
If you opt for pure virtual functions then you have to note, that this makes the class itself abstract, too, and you cannot make objects that are purely Persons (in our case), only sub-classes of it.