0

I think that I don't quite understand combining templating with derived classes. I suspect I am not using typename where I am supposed to.

With the following class that I've made:

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;
};

When I make a derived class such as the following, it compiles okay.

//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();
    }    
};

However, when I do the following, it doesn't compile:

//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();
    }
};

I've been trying different things but at this point I think I am just guessing. Any help would be appreciated!

Otto Nahmee
  • 133
  • 1
  • 2
  • 12
  • 1
    See "[*Where and why must I use `template` and `typename`?*](http://stackoverflow.com/a/24101297/1090079)". – Filip Roséen - refp Mar 06 '15 at 03:01
  • 1
    `Category` is a dependent name, so you need to specify that it names a type. `typename SuperBuffer::Category` – Mike Seymour Mar 06 '15 at 03:03
  • Thanks @MikeSeymour that was what I was missing. I also had to change `return SuperBuffer::buffer.full()` inside of `SuperCircularBuffer::full()` and also, thanks Filip for the link – Otto Nahmee Mar 06 '15 at 18:59

0 Answers0