title: Template Class error "Expected initializer before '<' token"
body: <p>I'm trying to build a class called ArrayBag, and I'm having trouble with my compiler giving me that error.</p>
  
  <p>The goal of the class is to be able to take in most simple data types in a catch all array.</p>
  
  <p>ArrayBag.cxx</p>
  
  <pre><code>//
  #include &lt;cstddef&gt;
  
  // Constructor; creates and initializes an empty Bag
  template &lt;class ItemType&gt;
  ArrayBag&lt;ItemType&gt;::ArrayBag()
  {
      itemCount = 0;
  }
  
  // Return the number of Items being stored in the Bag
  template &lt;class ItemType&gt;
  int ArrayBag&lt;ItemType&gt;::getCurrentSize() const
  {
      return itemCount;   // STUB
  }
  
  // Return the capacity of the bag (the maximum Items it can store) 
  template &lt;class ItemType&gt;
  int ArrayBag&lt;ItemType&gt;::getCapacity( ) const
  {
      return DEFAULT_CAPACITY;
  }
  
  // Report whether the Bag is empty
  // Return true if the Bag is empty (storing no Items);
  // Return false if Items exist in the Bag
  template &lt;class ItemType&gt;
  bool ArrayBag&lt;ItemType&gt;::isEmpty() const
  {
      return (itemCount == 0);
  }
  
  // Report whether the Bag is full
  // Return true if the Bag is filled to capacity
  // Return false if there is still room
  template &lt;class ItemType&gt;
  bool ArrayBag&lt;ItemType&gt;::isFull() const
  {
      return (itemCount == DEFAULT_CAPACITY); // STUB
  }
  
  // Give the Bag a new Item to store
  // If Bag is full, nothing changes
  // Else, Bag must add this Item to its Item array and update its itemCount
  // If Bag is full after this, return true; else return false
  template &lt;class ItemType&gt;
  bool ArrayBag&lt;ItemType&gt;::add(const ItemType&amp; newItem)
  {
      if(itemCount == DEFAULT_CAPACITY)
      {
          cout &lt;&lt; "The bag is full!" &lt;&lt; endl;
          return false;
      }
      else
      {
          items[itemCount] = newItem;
          itemCount++;
          return true;
      }
  }
  
  // Make the Bag act like an empty Bag again
  template &lt;class ItemType&gt;
  void ArrayBag&lt;ItemType&gt;::clear()
  {
      itemCount = 0;
  }
  
  // Remove an Item from the bag
  // If Item is not there, nothing changes and we return false
  // Else, we fill in its spot in that Item array and count number of Items down
  template &lt;class ItemType&gt;
  bool ArrayBag&lt;ItemType&gt;::remove(const ItemType&amp; anItem)
  {
      int index;
      for(int i=0; i&lt;=itemCount;i++)
      {
          index = i;
          if(items[i] == anItem)
          {
              break;
          }
          else
          {
              cout &lt;&lt; "Item not found in the bag bro." &lt;&lt; endl;
              return false;
          }
      }
      for(int i=index;i&lt;=itemCount;i++)
      {
          items[i] = items[i+1];
      }
      return true;
  }
  
  // Check if an Item is in the Bag
  // Return true if it is in the Bag, and false if not
  template &lt;class ItemType&gt;
  bool ArrayBag&lt;ItemType&gt;::contains(const ItemType&amp; anItem) const
  {
      for(int i = 0; i &lt;= DEFAULT_CAPACITY; i++)
          if(items[i] == anItem){
              return true;
          }
          return false;
      // STUB
  }
  
  // Check how many times an Item is in the Bag
  // return 0 if it's not there; otherwise,
  // return the number of times it occurs
  template &lt;class ItemType&gt;
  int ArrayBag&lt;ItemType&gt;::getFrequencyOf(const ItemType&amp; anItem) const
  {
      return 0;       // STUB
  }
  
  // Make an output vector of Items from the bag (for checking)
  template &lt;class ItemType&gt;
  vector&lt;ItemType&gt; ArrayBag&lt;ItemType&gt;::toVector() const
  {
      vector&lt;ItemType&gt; bagContents;
      // small STUB
      return bagContents;             
  }
  </code></pre>
  
  <p>ArrayBag.h</p>
  
  <pre><code>#ifndef _ARRAY_BAG
  #define _ARRAY_BAG
  
  #include "BagInterface.h"
  template&lt;class ItemType&gt;
  class ArrayBag : public BagInterface&lt;ItemType&gt;
  {
      private:
          static const int DEFAULT_CAPACITY = 25;
          ItemType items[DEFAULT_CAPACITY];
          int itemCount;
  
      public:
          ArrayBag();
          int getCurrentSize() const;
          int getCapacity() const;
          bool isEmpty() const;
          bool isFull() const;
          bool add(const ItemType&amp; newItem);
          bool remove(const ItemType&amp; anItem);
          void clear();
          bool contains(const ItemType&amp; anItem) const;
          int getFrequencyOf(const ItemType&amp; anItem) const;
          vector&lt;ItemType&gt; toVector() const;
  };
  
  #include "ArrayBag.cxx"
  #endif
  </code></pre>
  
  <p>BagInterface.h</p>
  
  <pre><code>//  Created by Frank M. Carrano and Tim Henry.
  //  Copyright (c) 2013 __Pearson Education__. All rights reserved.
  
  /** Listing 1-1.
      @file BagInterface.h */
  #ifndef _BAG_INTERFACE
  #define _BAG_INTERFACE
  
  #include &lt;vector&gt;
  using namespace std;
  
  template&lt;class ItemType&gt;
  class BagInterface
  {
  public:
     /** Gets the current number of entries in this bag.
      @return The integer number of entries currently in the bag. */
     virtual int getCurrentSize() const = 0;
  
     /** Sees whether this bag is empty.
      @return True if the bag is empty, or false if not. */
     virtual bool isEmpty() const = 0;
  
     /** Tells us the total capacity of the bag.
      @return DEFAULT CAPACITY. */
     virtual int getCapacity() const = 0;
  
     /** Sees whether this bag is full.
      @return True if the bag is full, or false if not. */
     virtual bool isFull() const = 0;
  
     /** Adds a new entry to this bag.
      @post  If successful, newEntry is stored in the bag and
         the count of items in the bag has increased by 1.
      @param newEntry  The object to be added as a new entry.
      @return  True if addition was successful, or false if not. */
     virtual bool add(const ItemType&amp; newEntry) = 0;
  
     /** Removes one occurrence of a given entry from this bag,
         if possible.
      @post  If successful, anEntry has been removed from the bag
         and the count of items in the bag has decreased by 1.
      @param anEntry  The entry to be removed.
      @return  True if removal was successful, or false if not. */
     virtual bool remove(const ItemType&amp; anEntry) = 0;
  
     /** Removes all entries from this bag.
      @post  Bag contains no items, and the count of items is 0. */
     virtual void clear() = 0;
  
     /** Counts the number of times a given entry appears in bag.
      @param anEntry  The entry to be counted.
      @return  The number of times anEntry appears in the bag. */
     virtual int getFrequencyOf(const ItemType&amp; anEntry) const = 0;
  
     /** Tests whether this bag contains a given entry.
      @param anEntry  The entry to locate.
      @return  True if bag contains anEntry, or false otherwise. */
     virtual bool contains(const ItemType&amp; anEntry) const = 0;
  
     /** Empties and then fills a given vector with all entries that
         are in this bag.
      @return  A vector containing all the entries in the bag. */
     virtual vector&lt;ItemType&gt; toVector() const = 0;
  }; // end BagInterface
  #endif
  </code></pre>
  
  <p>How can I fix this? I don't see what I'm doing wrong.</p>
  
  <p>Here are the errors.</p>
  
  <pre><code>Description Resource    Path    Location    Type
  'ArrayBag' does not name a type ArrayBag.cxx    /ArrayBag   line 6  C/C++ Problem
  'vector' does not name a type   ArrayBag.cxx    /ArrayBag   line 121    C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 114    C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 74 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 100    C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 48 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 65 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 29 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 38 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 13 C/C++ Problem
  expected initializer before '&lt;' token   ArrayBag.cxx    /ArrayBag   line 20 C/C++ Problem
  </code></pre>