Re: Diamond Inheritance and STL
HGallon@teranews.com wrote:
I have an application where I have visual elements which are a: Moving
or Stationary, and b: Static or Animated
<snip>
Dear All
Thanks for everyone's help. It is now clear to me that my design, rather
than any facet of virtual inheritance was at fault. A lot of code was
omitted from the sample code I provided, which may have hidden vital
details.
For what it is worth, my solution involved separating the image from the
element classes, and virtually inheriting a GetImage () function. I have
also separated the movement rules into a separate class so that I now have
class movingElement : public element, public movementRules
{
};
class animatedElement : public element
{
};
class movingAnimatedElement : public animatedElement, public movementRules
{
};
Instead of adding elements to the sorted list, I could then use:
class imageList
{
private:
std::list<image*> m_list; // all right, std::vector if you want
public:
void addImage (element& el);
};
void imageList::addImage (element& el)
{
image& img = element.getImage ();
// sort and list insertion code omitted
}