Advertisement

Multiple/Virtual inheritance

Started by May 26, 2001 01:06 PM
1 comment, last by Kosh 23 years, 8 months ago
hi guys ok, I''m wondering how I should use these two features, I have a good idea of normal inheritance that most people use, so I''ll explain my class heirarchy.... class PixelBuffer class DXPixelBuffer, virtual public PixelBuffer class ImagePixelBuffer, virtual public PixelBuffer class DXImagePixelBuffer, public ImagePixelBuffer, public DXPixelBuffer so, ill give you an explanation of what each class is supposed to be doing PixelBuffer is the base class of the whole system, all are derived from this base class DXPixelBuffer inherits the interface from PixelBuffer and implements the actual buffer object, this is a DirectDraw system, so it''s using IDirectDrawSurface7 *surface''s ImagePixelBuffer inherits and extends the PixelBuffer object by giving you one extra function, LoadImage, this has the following function prototype: virtual bool LoadImage(char *filename, char *dll_filename); filename, obviously means the filename of the Image you want to load, the dll_filename means the dll you request to load the file for you, you basically ask the dll for a handle to a file, it''ll read your filename, read/open/decode and pass back through a inherited class object the data contained in the file, please, it gets a little more complex than that, I dont think you need to know the dirty work DXImagePixelBuffer has to multiply inherit both those two classes, because firstly the object needs PixelBuffer capabilities, which is fine, but unless I plan to put the implementation in the DXImagePixelBuffer class, I have to inherit from a lower class which already implements, it, hence DXPixelBuffer rather PixelBuffer, inheriting ImagePixelBuffer is just like normal, the implementation of ImagePixelBuffer is done in the DXImagePixelBuffer class. ok, was that clear enough? right, ok, now, does that heirarchy look ok to you? or does it look wrong? right, now saying that, I think there is something wrong, do any of you know what the fuck _purecall() is ? well, when I try to construct an object of type DXImagePixelBuffer, assigning it to a ImagePixelBuffer ptr, the ImagePixelBuffer and DXImagePixelBuffer''s vtable gets filled with this _purecall() function, not knowing what this means, I''m stumped, can anyone else explain why I''m getting that function inserted rather than my normal functions I''ve defined in my classes ? I reckon it''ll take someone here about 10 seconds to find out where I''ve gone wrong, this is my first real attempt at this, so if you can help me out, that''d be great, thanks ! kosh
if understanding it made and born with time, then time, is understandings greatest enemy.....
don''t think I''m answering your question very well, but my advice is to avoid multiple inheritance. You''re going to give yourself needless headaches...

For instance, if you typecast a derived pointer to a base pointer, there''s no guarantee that it''s still pointing at the same address because with multiple inheritance there are multiple vtables for the object. Stuff like that should turn you off.
Advertisement
well , in a way, dont use inheritance , but use composition..
check out the composition pattern in the design patterns section..

should solve your problem of a class having defined the same parent twice ..


{ Stating the obvious never helped any situation !! }

This topic is closed to new replies.

Advertisement