Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lightrocker

Derivation

This topic is 5882 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

I have declared two interfaces like that: interface IBase { virtual int FunctionOne( ... ) = 0; }; interface IExtended : IBase { virtual int FunctionTwo( ... ) = 0; }; Then there are two classes: class CBase : public IBase { public: int FunctionOne( ... ); }; class CExtended : public CBase, public IExtended { public: int FunctionOne( ... ); // without that line I get an error int FunctionTwo( ... ); }; This is a part of the implementation: int CExtended::FunctionOne( ... ) { return CBase::FunctionOne( ... ); } Is there a way, in which I don't have to define FunctionOne() in CExtended but can call it over the interface IExtended? The method of class CBase should be called directly. [edited by - Lightrocker on August 14, 2002 4:06:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
i know i''m too lazy to open msvc and test this out first, but try putting a using-directive in your CExtended class like so:

using CBase::FunctionOne;

i give no guarantees that this will work.

Share this post


Link to post
Share on other sites
CExtended is inheriting a FunctionOne via two routes: CBase, and IExtended. The version of FunctionOne inherited via IExtended has no over-ride, so is still abstract. You seem to be expecting that CExtended will mix-in CBase and take the implementation of FunctionOne from there, but haven''t realised you have two different IBase objects within the overall object representation. To ensure that you only get one IBase within the object rep, you need to specify that derived classes are to share the same IBase, and you can do that using virtual inheritance. Change the IBase derivations to be:

interface IExtended : virtual IBase

and

class CBase : public virtual IBase

Share this post


Link to post
Share on other sites
It was a good idea, niyaw, but it doesn''t work with pure virtual methods, which I need for a DLL interface.
Thank you, SabreMan, you are right and now my code is running like I want it to do.

Share this post


Link to post
Share on other sites

  • 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!