Jump to content
  • Advertisement
Sign in to follow this  
Rebooted

Multiple Inheritance Problem

This topic is 5040 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 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
Advertisement
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
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!