接口实现 [英] Interface implementation
问题描述
大家好。我对接口实现有一些疑问,如果
任何人都可以帮助我,我会非常感谢。
所以:
如果我有一些接口IA:
class IA
{
virtual void SomePureVirtFunc()= 0;
};
和一些B类,实现了该界面:
B级:公共IA
{
虚拟空虚SomePureVirtFunc(){};
};
现在我需要在C类继承自接口ITwoInOne,从IA继承了
。
问题:这是任何方法,继承自ITwoInOne接口,并且
不要实现接口IA,但是使用多继承 - 从B类继承
,已经实现了该接口,并满足我的
要求?
换句话说:我能写出类似的东西:
class NewOne:public B
,public ITwoInOne
{
//仅实现纯虚函数
//,不对应IA接口
}
P.S.抱歉混淆,以及我的英语不好。
Hi all. I have some questions about interface implementation, if
anybody can help me, I will be very thank.
So:
If i have some interface IA:
class IA
{
virtual void SomePureVirtFunc() = 0;
};
and some class B, that implemented that interface:
class B : public IA
{
virtual void SomePureVirtFunc() {};
};
Now I need in class C inherit from interface ITwoInOne, that inherited
from IA also.
Question: it is any method, inherit from interface ITwoInOne, and
don''t implement interface IA, but using multiple inheritance - inherit
from class B, that already implemented that interface, and satisfy my
requirements?
Another words: can I write something like that:
class NewOne : public B
, public ITwoInOne
{
//Implementation only pure virtual functions
//, that not correspond to IA interface
}
P.S. sorry for confusion, and for my bad English.
推荐答案
Galian写道:
Galian wrote:
大家好。我对接口实现有一些疑问,如果
任何人都可以帮助我,我会非常感谢。
所以:
如果我有一些接口IA:
class IA
{
virtual void SomePureVirtFunc()= 0;
};
和一些B类,实现了该界面:
B级:公共IA
{
虚拟空虚SomePureVirtFunc(){};
};
现在我需要在C类继承自接口ITwoInOne,从IA继承了
。
问题:这是任何方法,继承自ITwoInOne接口,并且
不要实现接口IA,但使用多继承 - 从B类继承
,已经实现了该接口,并满足我的
要求?
Hi all. I have some questions about interface implementation, if
anybody can help me, I will be very thank.
So:
If i have some interface IA:
class IA
{
virtual void SomePureVirtFunc() = 0;
};
and some class B, that implemented that interface:
class B : public IA
{
virtual void SomePureVirtFunc() {};
};
Now I need in class C inherit from interface ITwoInOne, that inherited
from IA also.
Question: it is any method, inherit from interface ITwoInOne, and
don''t implement interface IA, but using multiple inheritance - inherit
from class B, that already implemented that interface, and satisfy my
requirements?
是的,从IA _virtually_ *继承*。即虚拟地使B继承自
IA并使ITwoInOne虚拟继承。
Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit from
IA virtually and make ITwoInOne inherit virtually.
>
另一个词:can我写的是这样的:
class NewOne:public B
,public ITwoInOne
{
//仅实现纯虚函数
//,不对应IA接口
}
PS对不起困惑,我的英语不好。
>
Another words: can I write something like that:
class NewOne : public B
, public ITwoInOne
{
//Implementation only pure virtual functions
//, that not correspond to IA interface
}
P.S. sorry for confusion, and for my bad English.
V
-
请在通过电子邮件回复时删除资金'A'
我没有回复最热门的回复,请不要问
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
是的,继承IA _virtually_ *到处*。即使B继承自
Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit from
IA虚拟化并使ITwoInOne虚拟继承。
IA virtually and make ITwoInOne inherit virtually.
所以这是正确的方式:
B级:公共虚拟IA
{< br $>
};
类NewOne:公共虚拟B
,公共虚拟ITwoInOne
{
};
这是对的吗?
如果是,那么问题:是课程的顺序继承是否重要?
我的意思是,如果我先写公共虚拟ITwoInOne,而不是
" public virtual B"
So this is right way:
class B : public virtual IA
{
};
class NewOne : public virtual B
, public virtual ITwoInOne
{
};
Is this right?
If yes, than question: is order of classes for inheritance important?
I mean it is OK if I write first "public virtual ITwoInOne", and than
"public virtual B"?
Galian写道:
Galian wrote:
>是的,继承自IA _virtually_ *到处*。即让B虚拟地从IA继承
并使ITwoInOne虚拟地继承。
>Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit
from IA virtually and make ITwoInOne inherit virtually.
所以这是正确的方式:
B级:公共虚拟IA
{< br $>
};
类NewOne:公共虚拟B
,公共虚拟ITwoInOne
{
};
这是对的吗?
如果是,那么问题:是课程的顺序继承重要吗?
我的意思是,如果我先写public virtual ITwoInOne,而不是
" public virtual B"
So this is right way:
class B : public virtual IA
{
};
class NewOne : public virtual B
, public virtual ITwoInOne
{
};
Is this right?
If yes, than question: is order of classes for inheritance important?
I mean it is OK if I write first "public virtual ITwoInOne", and than
"public virtual B"?
我认为订单并不重要。你试过吗?如果你有
,并且成功取决于订单,请你分享一下吗?
如果你还没试过,为什么?
>
V
-
请在通过电子邮件回复时删除资金''A'
我不知道回复最热门的回复,请不要问
I think that the order is not significant. Have you tried it? If you
have, and the success depended on the order, could you please share?
If you haven''t tried, why?
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
这篇关于接口实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!