Original Post
Hi, I have a set of interfaces (pure virtual methods) with an inheritance relationship: MSVC++ raises a runtime exception. I have read something about...This kind of situation is called the "dreaded diamond". I have read that using virtual inheritance from IBaseTexture will help... But I cannot change the code of ITexture, ICubeTexture and IVolumeTexture. Any kind of help, even involving paranormal powers, will be appreciated. Thanks, Chema [Edited by - chema on March 29, 2007 8:32:14 AM]
+--------------+
| IBaseTexture |
+--------------+
^
|
+--------------+-------------------+
| | |
+--------------+ +---------------+ +----------------+
| ITexture | | ICubeTexture | | IVolumeTexture |
+--------------+ +---------------+ +----------------+
I want to write implementation classes for ITexture, ICubeTexture and IVolumeTexture so I added:
+--------------+
| IBaseTexture |
+--------------+
^
|
+--------------+-------------------+
| | |
+--------------+ +---------------+ +----------------+
| ITexture | | ICubeTexture | | IVolumeTexture |
+--------------+ +---------------+ +----------------+
^ ^ ^
| | |
+--------------+ +---------------+ +-----------------+
| MyTexture | | MyCubeTexture | | MyVolumeTexture |
+--------------+ +---------------+ +-----------------+
But I want to make a common base interface for MyTexture, MyCubeTexture and MyVolumeTexture. So I added the IMyBaseTexture interface.
+--------------+ +------------------+
| IBaseTexture |<---------------------| IMyBaseTexture |
+--------------+ +------------------+
^ + draw() = 0 |
| +------------------+
+--------------+-------------------+ ^
| | | |
+--------------+ +---------------+ +----------------+ |
| ITexture | | ICubeTexture | | IVolumeTexture | |
+--------------+ +---------------+ +----------------+ |
^ ^ ^ |
| +------------|---+---------------|---+--------------+
| | | | | |
+--------------+ +---------------+ +-----------------+
| MyTexture | | MyCubeTexture | | MyVolumeTexture |
+--------------+ +---------------+ +-----------------+
| draw() | | draw() | | draw() |
+--------------+ +---------------+ +-----------------+
The problem is: In some point of my program I need to cast a IBaseTexture pointer to a IMyBaseTexture pointer.
void draw(IBaseTexture *i_base_texture) {
BaseTexture *base_texture = dynamic_cast<BaseTexture *>(i_base_texture);
base_texture->draw();
}