从不同的基类重载相同名称的虚函数。是否可以? [英] Overloading virtual functions of the same name from different base classes. Is it possible?
本文介绍了从不同的基类重载相同名称的虚函数。是否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有以下设置:
class A
{
public:
virtual void fn()= 0;
};
class B
{
public:
virtual int fn(){};
};
class C:public A,public B
{
};
有任何方法来定义 A :: fn
fn()
中的任何一个冲突。
fn ()
不同,
void fn // in A
和 B
,
int fn(); // in B
你必须使这些语法在 code>和
B
让 C
实现 fn c $ c>。 演示。
The title is probably confusing.
Suppose we have the following set up;
class A
{
public:
virtual void fn() = 0;
};
class B
{
public:
virtual int fn() {};
};
class C: public A, public B
{
};
Is there any way to define A::fn
in class C
?
解决方案
No. This is not possible. It will always conflict with either of the fn()
.
The syntax of fn()
are different,
void fn(); // in A
and in B
is,
int fn(); // in B
You have to make those syntax same in A
and B
to let C
implement the fn()
. Demo.
这篇关于从不同的基类重载相同名称的虚函数。是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文