I ran into a specific problem regarding virtual inheritance. The code below explains the structure.
// Header
struct ITarget
{
virtual void SetValue() = 0;
};
struct ISource
{
virtual void GetValue() const = 0;
};
struct IBase
{
virtual void Stuff() = 0;
};
struct IInput :
virtual public IBase, public ITarget
{
// Publicly acts only as Target
};
struct IOutput :
virtual public IBase, public ISource
{
// Publicly acts only as Source
};
// Implementation
struct SBase :
virtual public IBase, virtual public ISource, virtual public ITarget
{
// IBase
virtual void Stuff();
// ISource
virtual void GetValue() const;
// ITarget
virtual void SetValue( );
};
struct SInput :
public IInput, public SBase
{
// Defines ITarget and ISource per SBase
};
struct SOutput :
public IOutput, public SBase
{
// Defines ITarget and ISource per SBase
};
int main()
{
// To demonstrate the behavior
ISource* input = new SInput();
((SInput*)input)->GetValue();
return 0;
}
Now, if I want to cast an ISource* to an SInput*, I get error C2635:
"cannot convert a 'ISource*' to a 'SInput*'; conversion from a virtual base class is implied"
How exactly do I have to set up the inheritance to make this possible?