请看继承:
interface IArray
{
virtual unsigned __int8* GetAddress() const = 0;
virtual unsigned int GetItemCount() const = 0;
virtual unsigned int GetItemSize() const = 0;
};
template<class T>
class CustomArrayT : public IArray
{
public:
virtual unsigned __int8* GetAddress() const;
virtual unsigned int GetItemCount() const;
virtual unsigned int GetItemSize() const;
T& GetItem(unsigned int index);
};
interface IFloatArray : public CustomArrayT<float>
{
virtual IFloatArray* GetCompressedData() const = 0;
};
class ShannonFloatArray : public IFloatArray
{
public:
virtual IFloatArray* GetCompressedData() const;
};
class FourierFloatArray : public IFloatArray
{
public:
virtual IFloatArray* GetCompressedData() const;
};
class MickyMouseFloatArray : public IFloatArray
{
public:
virtual IFloatArray* GetCompressedData() const;
};
问题的主要目标是继承IFloatArray -> CustomArrayT:接口继承了一些非抽象类。我不想支持多重继承。但是我需要所有的 downtree 类都具有类 CustomArrayT 的功能并实现接口 IFloatArray。
这种树有什么优缺点?
怎么可能用另一种方式来完成?也许是某种模式?