class A
{
public:
virtual void D(int j) = 0;
}
class B : virtual public A
{
public:
virtual void D(int j);
}
class C : virtual public A
{
public:
virtual void D();
}
class E : public B , public C
{
// ...
}
calling interface functions with the same name
I'm pretty sure you can't, then it'ld be impossible to make an object of the type C because it can't call "void B::D(int j)". If C needs to call a function inside B, C should inherit from B.
EDIT: Well know that I think about it I don't really know what you mean, does you mean this:
or this:
The second example would be possible, but the first won't.
[Edited by - CTar on June 7, 2005 2:42:09 PM]
EDIT: Well know that I think about it I don't really know what you mean, does you mean this:
class C : public A{ public: virtual void D() { D(42); }}
or this:
class E : public C,public B{ public: virtual void D() { D(42); }}
The second example would be possible, but the first won't.
[Edited by - CTar on June 7, 2005 2:42:09 PM]
Example:
output:
B::D Called
C::D Called
class A{ public: virtual void D(int j) = 0;};class B : virtual public A{ public: virtual void D(int j) { printf("B::D Called\r\n"); };};class C : virtual public A{ public: virtual void D() { printf("C::D Called\r\n"); }};class E : public B , public C{public: void test() { B::D(1); C::D(); }};/// .. elsewhereE e;e.test();
output:
B::D Called
C::D Called
sorry for my horrible minimal wording.
basically i wanted to from within E call C::D() which calls the overriden A::D(int) or B::D(int).
but as some of you have said... this isn't possible unless I change the name of A::D(int)?
basically i wanted to from within E call C::D() which calls the overriden A::D(int) or B::D(int).
but as some of you have said... this isn't possible unless I change the name of A::D(int)?
Quote:Original post by Genjix
sorry for my horrible minimal wording.
basically i wanted to from within E call C::D() which calls the overriden A::D(int) or B::D(int).
but as some of you have said... this isn't possible unless I change the name of A::D(int)?
Ah.. you want C::D to call B::D.. nope, can't be done.. or it would involve some serious hacks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement