So I am new to the concept of virtual functions in C++, and threads like this do a good job of selling this concept. Ok I am convinced.
But why are virtual functions called 'virtual'? I mean such functions are as 'concrete' as usual functions / methods aren't they? If someone could explain the choice of the word 'virtual' for naming this concept, that would be great.
'virtual function' means a member function where the specific implementation will depend on the type of the object it is called upon, at run-time. The compiler and run-time support of the language contrive to make this happen. The keyword 'virtual' in C++ was taken from Simula, which had impressed Bjarne Stroustrup.
A virtual function is a member function which is declared within a base class and is re-defined (overridden) by a derived class.
Yes virtual function used for polymorphism can return any type, instead of being a void.
Virtual functions are functions that can be overridden in derived class with the same signature. Virtual functions enable run-time polymorphism in a inheritance hierarchy.
Virtuality, the quality of having the attributes of something without sharing its (real or imagined) physical form
^ http://en.wikipedia.org/wiki/Virtual
A C++ virtual function appears to be an ordinary function ("having the attributes of"), but the implementation that will be called is not shared out via the declaration, or for that matter via an inline implementation.
'virtual function' means a member function where the specific implementation will depend on the type of the object it is called upon, at run-time. The compiler and run-time support of the language contrive to make this happen.
The keyword 'virtual' in C++ was taken from Simula, which had impressed Bjarne Stroustrup. Lots more background here: Pure virtual or abstract, what's in a name?
.. the SIMULA 67 Common Base Language (1970) .. seems to be the first language to introduce OO keywords as class, object, and also virtual as a formal concept.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With