模板化继承类的错误

时间:2015-03-06 02:35:59

标签: c++ templates derived-class

我认为我并不完全理解将模板与派生类相结合。我怀疑我没有使用我应该使用的typename。

我已经完成了以下课程:

template <typename T>
struct NumericStruct
{
  public:
    NumericStruct():
      value(0),
      index(0) {}

    T value
    unsigned int index;
};


template <typename T, template <typename, typename = std::allocator<NumericStruct<T> > > class Container>
class SuperBuffer
{
  public:
    enum Category
    {
      THIS = 0,
      THAT
    };

    SuperBuffer(const Category cat):
      category(cat),
      buffer() {}

    void push_back( T number, unsigned int index );
    T calculate() const;

  protected:

    Category category;
    Container<NumericStruct<T> > buffer;
};

当我创建如下所示的派生类时,它编译好了。

//THIS IS OKAY
class SuperCircularBuffer : public SuperBuffer<double, boost::circular_buffer>
{
  public:
    SuperCircularBuffer(SuperBuffer<double, boost::circular_buffer>::Category type = SuperBuffer<double, boost::circular_buffer>::THIS):
      SuperBuffer<double, boost::circular_buffer>(type)
    {};

    bool full() const
    {
      return buffer.full();
    }    
};

但是,当我执行以下操作时,它不会编译:

//COMPILER COMPLAINS ABOUT THIS
template <typename T = double>
class SuperCircularBuffer : public SuperBuffer<T, boost::circular_buffer>
{
  public:
    SuperCircularBuffer(SuperBuffer<T, boost::circular_buffer>::Category type = SuperBuffer<T, boost::circular_buffer>::THIS):
      SuperBuffer<T, boost::circular_buffer>(type)
    {};

    bool full() const
    {
      return buffer.full();
    }
};

我一直在尝试不同的事情,但在这一点上,我想我只是在猜测。任何帮助将不胜感激!

0 个答案:

没有答案