Sign in to follow this  
Rebooted

Multiple Inheritance Problem

Recommended Posts

Rebooted    612
I don't usually use multiple inheritance, but I thought it was necessary for this situation. I have written a cross platform dynamic library manager that lets me load a DLL and get an object of type Interface (similar to COM) from it in just a few lines. I have a class called DynamicLibHandle that abstracts a DLL and provides functions to open it, close it and request interfaces from it. I was including the whole of this class and its implementation into the DLL but to remove unnecessary code and reduce the size of the DLL I decided to make an abstract base class and only include the real class in the main program, and not into every DLL. This is my base class, it provides only the functions a DLL needs access to:
class IDynamicLibHandle
{
	public:
		// move Interface onto deadlist to be garbage collected next frame

		virtual void ReleaseInterface(Interface *interface_ptr) = 0;


		// ref counting functions, usual called automatically by a SmartPointer
		// implememented when DynamicLibHandle inherits MemObject

		virtual void AddRef() = 0;
		virtual void Release() = 0;
};


The real class inherits from this, and implements ReleaseInterface(). It also inherits from MemObject (based on the Enginuity version), which implements AddRef() and Release():
class DynamicLibHandle : public MemObject, public IDynamicLibHandle
However, inside my main program I get errors. DynamicLibHandle cannot be instantiated, because AddRef() and Release() are abstract in IDynamicLibHandle. Is there any way to solve this, so that AddRef() and Release() are implemented correctly by inheriting MemObject? I apologise for my long and probably confusing post.

Share this post


Link to post
Share on other sites
Quote:
Original post by Shard
Is there any way to solve this, so that AddRef() and Release() are implemented correctly by inheriting MemObject?


You have to implement a function in the child which internally just calls MemObject's corresponding functions, IE:

class DynamicLibHandle
: public MemObject
, public IDynamicLibHandle
{
public:
void AddRef() { MemObject::AddRef(); }
void Release() { MemObject::Release(); }
};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this