为什么c++中的虚函数被称为“虚”?

时间:2022-11-25 16:54:45

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.

因此,我对c++中的虚函数概念并不熟悉,像这样的线程很好地推销了这个概念。好吧我相信。

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.

但是为什么虚函数被称为“虚函数”呢?我的意思是这些函数和通常的函数/方法一样是“具体的”,不是吗?如果有人能解释“虚拟”这个词的命名,那就太棒了。

2 个解决方案

#1


10  

Virtuality, the quality of having the attributes of something without sharing its (real or imagined) physical form

虚拟性,不共享(真实的或想象的)物理形式的东西的属性的质量

^ http://en.wikipedia.org/wiki/Virtual

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

c++虚函数看起来是一个普通的函数(“具有of的属性”),但是要调用的实现不会通过声明共享,或者通过内联实现共享。

#2


7  

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

c++中关键字“virtual”取自Simula,它给Bjarne Stroustrup留下了深刻的印象。这里有更多的背景:纯粹的虚拟或抽象,名字里有什么?

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

. .SIMULA 67通用基语(1970)。似乎是第一个将OO关键字引入类、对象和虚拟形式的语言。

#1


10  

Virtuality, the quality of having the attributes of something without sharing its (real or imagined) physical form

虚拟性,不共享(真实的或想象的)物理形式的东西的属性的质量

^ http://en.wikipedia.org/wiki/Virtual

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

c++虚函数看起来是一个普通的函数(“具有of的属性”),但是要调用的实现不会通过声明共享,或者通过内联实现共享。

#2


7  

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

c++中关键字“virtual”取自Simula,它给Bjarne Stroustrup留下了深刻的印象。这里有更多的背景:纯粹的虚拟或抽象,名字里有什么?

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

. .SIMULA 67通用基语(1970)。似乎是第一个将OO关键字引入类、对象和虚拟形式的语言。