Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are virtual functions in C++ called 'virtual'? [closed]

Tags:

c++

virtual

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.

like image 258
curiousexplorer Avatar asked Jul 21 '12 17:07

curiousexplorer


People also ask

Why virtual function is called Virtual?

'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.

What is a virtual function in C?

A virtual function is a member function which is declared within a base class and is re-defined (overridden) by a derived class.

Are virtual functions always void?

Yes virtual function used for polymorphism can return any type, instead of being a void.

What is the virtual function in C Mcq?

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.


2 Answers

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.

like image 131
Cheers and hth. - Alf Avatar answered Sep 20 '22 06:09

Cheers and hth. - Alf


'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.

like image 25
Bryan Avatar answered Sep 23 '22 06:09

Bryan