About abstract classes inheritance
Hi,
I have a little problem with a tree of abstract classes.
My interfaces definitions are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
struct IAudioDevice
{
virtual void IAudioDeviceMethod() = 0;
}
//----------------------------------------------------------------
struct IAudioRecorder : virtual public IAudioDevice
{
virtual void IAudioRecorderMethod() = 0;
}
//----------------------------------------------------------------
struct ICodec
{
virtual void ICodecMethod() = 0;
};
//----------------------------------------------------------------
struct IAudioDecoder : public ICodec, public virtual IAudioRecorder
{
virtual void IAudioDecoderMethod() = 0;
};
//----------------------------------------------------------------
struct IAudioInputRepeater : public IAudioDecoder
{
virtual void IAudioInputRepeaterMethod() = 0;
};
|
and the implementation is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
class AudioDevice : virtual public IAudioDevice
{
public:
void IAudioDeviceMethod() { /* IMPLEMENTATION */ };
};
//----------------------------------------------------------------
class AudioRecorder : public IAudioRecorder,
public AudioDevice
{
public:
void IAudioRecorderMethod() { /* IMPLEMENTATION */ };
};
//----------------------------------------------------------------
class AudioDecoder : public AudioRecorder,
public IAudioDecoder
{
public:
virtual void IAudioDecoderMethod() { /* IMPLEMENTATION */ };
virtual void ICodecMethod() { /* IMPLEMENTATION */ };
};
//----------------------------------------------------------------
class AudioInputRepeater : public IAudioInputRepeater,
public AudioDecoder
{
public:
void IAudioInputRepeaterMethod() { /* IMPLEMENTATION */ };
};
|
When I try to instantiate an AudioInputRepeater object the compiler raise the error:
"cannot instantiate abstract class due to following members:"
ICodec::ICodecMethod()
IAudioDecoder::IAudioDecoderMethod()
Why this happen?
This class is derived from the concrete class AudioDecoder which defines these methods!
Regards,
Daniele.
Ok,
I answer to myself! :-)
I simply forgot a "virtual" keyword:
1 2 3 4
|
struct IAudioDecoder : public virtual ICodec, public virtual IAudioRecorder
{
virtual void IAudioDecoderMethod() = 0;
};
|
Daniele.
Topic archived. No new replies allowed.