C++ 中的虚函数实例化有什么区别? [英] What's the difference between virtual function instantiations in C++?

查看:38
本文介绍了C++ 中的虚函数实例化有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两个声明有什么区别?

What's the difference between the following two declarations?

virtual void calculateBase() = 0;  
virtual void calculateBase();

我读到第一个 (=0) 是一个纯抽象函数",但第二个是什么?

I read the first one (=0) is a "pure abstract function" but what does that make the second one?

推荐答案

第一个叫做纯虚函数.通常纯虚函数不会有任何实现,您不能创建包含纯虚函数的类的实例.

First one is called a pure virtual function. Normally pure virtual functions will not have any implementation and you can not create a instance of a class containing a pure virtual function.

第二个是虚函数(即普通"虚函数).一个类提供了这个函数的实现,但是它的派生类可以通过为这个方法提供自己的实现来覆盖这个实现.

Second one is a virtual function (i.e. a 'normal' virtual function). A class provides the implementation for this function, but its derived class can override this implementation by providing its own implementation for this method.

这篇关于C++ 中的虚函数实例化有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆