Archived

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

Lightrocker

Derivation

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