我们可以在定义虚函数的类中使用虚函数吗? [英] Can we use a virtual function in the class in which the virtual function is defined?
本文介绍了我们可以在定义虚函数的类中使用虚函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
展开 | 选择 | Wrap | 行号
推荐答案
你有一个分号在这一行的末尾:
Hi,
You have a semicolon at the end of this line:
展开 | 选择 | Wrap | 行号
您可能无法理解虚拟目的函数。
当从指向对象基部的指针访问对象的派生部分时,使用虚函数。这就是允许C ++中的多态性的原因。
因此,不允许使用定义它的类的对象来调用虚函数。
但是,您可以从一个原始对象中的成员函数调用基类虚函数:
You may not understand the purpose of a virtual function.
A virtual function is used when the derived portion of an object is accessed from a pointer to the base portion of the object. This is what allows polymorphism in C++.
Therefore, you are not allowed to call a virtual function using an object of the class that defines it.
You can, however, call a base class virtual function from a member function in a derved object:
展开 | 选择 | 换行 | 行号
感谢您的回复,但我已经知道您刚刚说了什么。
Thanks for your reply, but I already knew what you just said.
这篇关于我们可以在定义虚函数的类中使用虚函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文