Jump to content
  • Advertisement
Sign in to follow this  
Genjix

calling interface functions with the same name

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
{
	// ...
}


is there any way I can get C::D() to call B::D(int j) when in E, without changing the function names so they are different?

Share this post


Link to post
Share on other sites
Advertisement
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:

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]

Share this post


Link to post
Share on other sites
Example:

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();
}
};

/// .. elsewhere
E e;
e.test();




output:
B::D Called
C::D Called

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You may also want to look at virtual inheritance for this situation.

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I take it this is another 'deliberate' feature of C++ set by the standard? Is there any reason this is so?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!