Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类中间树(C+;+;)中的接口声明_C++_Class_Inheritance_Interface_Declaration - Fatal编程技术网

C++ 类中间树(C+;+;)中的接口声明

C++ 类中间树(C+;+;)中的接口声明,c++,class,inheritance,interface,declaration,C++,Class,Inheritance,Interface,Declaration,请看遗产: 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:

请看遗产:

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;
};
interface-ray
{
虚拟无符号uu int8*GetAddress()常量=0;
虚拟无符号int GetItemCount()常量=0;
虚拟无符号int GetItemSize()常量=0;
};
模板
类customarray:public-IArray
{
公众:
虚拟无符号uu int8*GetAddress()常量;
虚拟无符号int GetItemCount()常量;
虚拟无符号int GetItemSize()常量;
T&GetItem(无符号整数索引);
};
接口IFloatArray:public CustomArrayT
{
虚拟阵列*GetCompressedData()常量=0;
};
非浮点数组类:公共数组
{
公众:
虚拟IFloatArray*GetCompressedData()常量;
};
类FourierFloatArray:公共数组
{
公众:
虚拟IFloatArray*GetCompressedData()常量;
};
MickMyMouseFloatArray类:公共IFloatArray
{
公众:
虚拟IFloatArray*GetCompressedData()常量;
};
问题的主要目标是继承IFloatArray->CustomArrayT:接口继承一些非抽象类。我不想支持多重继承。但我需要所有的downtree类都具有CustomArrayT类的功能,并实现接口IFloatArray

这种树有什么优点和缺点


怎么能用另一种方法呢?也许是某种模式?

我会这样做:

template<class T>
class IArray {
public:
  virtual int size() const=0;
  virtual T map(int index) const=0;
};
模板
IArray类{
公众:
虚拟整数大小()常量=0;
虚拟T映射(int索引)常量=0;
};

所有的指针都是不必要的。

您的继承人身份的一个问题就是IArray接口到底用于什么

如果您希望将任何实例化的派生类作为引用或指针传递给IArray,那么您就不能从多态性中获益,因为您需要在添加或检索任何包含的值之前进行向下转换。(因为IArray不能在不声明要获取或设置的类型的情况下定义getter或setter函数,而该类型取决于实例化的派生类。)

为什么基类不能被模板化?“基类”应该是CustomArray,“派生”类可以说是typedefs


为什么不使用std::vector呢?(可能是为了练习。)

为什么不使用多重继承?好主意。但我需要指针是可访问的,并且基本接口不是模板化的+1用于映射;)也许考虑把数组和指针放在分离对象上。