title: Why am I getting the error: invalid use of member (did you forget the ‘&’ ?)?
body: <p>This is my first time asking a question, so forgive me if I format the post wrong. </p>
  
  <p>I'm doing an assignment to create my own version of the Queue class from the standard template library in C++. I wrote a private member function that returns an index to the tail end of the data stored in the array (for this assignment we are to use an array instead of a linked list, although it would make more sense to do the latter). </p>
  
  <p>The problem is that when I call this private member function I get the error: invalid use of member (did you forget the ‘&amp;’ ?). I'm not sure if this is because of the way I declared the function in the class definition or if I'm calling it wrong within another function. Here's the code (the problematic function <code>int tailIndex()</code> is at the end of the code block):</p>
  
  <pre><code>// QUEUE
  template &lt;class T&gt;
  class Queue
  {
    public:
     // default constructor : empty and kinda useless
    Queue() : numPop(0), numPush(0), mCapacity(0), data(0x00000000) {}
  
     // copy constructor
     Queue(const Queue &amp; rhs) throw (const char *) :
        mCapacity(0), data(0x00000000) { *this = rhs; }
  
     // non-default constructor : pre-allocate memory
     Queue(int capacity) throw (const char *);
  
     // destructor : free everything
     ~Queue()             { if (mCapacity) delete [] data; }
  </code></pre>
  
  <p>... skipping a few methods to get to the problem...</p>
  
  <pre><code>  private:
     T * data;          // dynamically allocated array of T
     int numPush;       // number of items pushed so far
     int numPop;        // number of items popped so far 
     int mCapacity;     // how many items can I put on the Queue before full
  
     // double the allocated memory
     void resize() throw (const char *); 
  
     // return an index to the head
     int headIndex() const { return numPop % capacity;        }
  
     // return an index to the tail
     int tailIndex() const { return (numPush - 1) % capacity; }
  };
  </code></pre>
  
  <p>The problem is <code>tailIndex()</code>. When I call it later on in a member function it gives the error. Although I don't think it's necessary, here is the function call:</p>
  
  <pre><code>int index = tailIndex() + 1;
  </code></pre>
  
  <p>Here is the exact output I'm getting from the compiler if that would be helpful:</p>
  
  <pre><code>queue.h: In member function ‘int&amp; Queue&lt;T&gt;::tailIndex() const [with T = int]’:
  queue.h:229:   instantiated from ‘void Queue&lt;T&gt;::push(const T&amp;) [with T = int]’
  qTest.cpp:18:   instantiated from here
  queue.h:96: error: invalid use of member (did you forget the ‘&amp;’ ?)
  </code></pre>
  
  <p>That's about it. Thank you for taking the time to review this problem. </p>