title: Template errors c++
body: <p>I am having some trouble with templates. for some reason my template itself seems to be fine but when I try to use it for some reason it errors out even though as far as I know I am using it correctly. The template is for a simple linked list that is meant to hold a child Shape classes and a CustomShape class. This code is for school so if you could only comment on the errors related to the template that would be great. I have read other posts on this subject but none seem to help/solve whatever my issue is.</p>
  
  <p>Errors using Visual Studio 2015:</p>
  
  <pre><code>1&gt;------ Build started: Project: a2_warn1700, Configuration: Debug Win32 ------
  1&gt;  LinkedList.cpp
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2143: syntax error: missing ';' before '&lt;'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2238: unexpected token(s) preceding ';'
  1&gt;  Generating Code...
  1&gt;  Compiling...
  1&gt;  CustomShape.cpp
  1&gt;  Generating Code...
  1&gt;  Compiling...
  1&gt;  main.cpp
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2143: syntax error: missing ';' before '&lt;'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2238: unexpected token(s) preceding ';'
  1&gt;  World.cpp
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2143: syntax error: missing ';' before '&lt;'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(14): error C2238: unexpected token(s) preceding ';'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(17): error C2039: 'shapeComponents': is not a member of 'CustomShape'
  1&gt;  c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(9): note: see declaration of 'CustomShape'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(17): error C2228: left of '.isNext' must have class/struct/union
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(18): error C2039: 'shapeComponents': is not a member of 'CustomShape'
  1&gt;  c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\customshape.h(9): note: see declaration of 'CustomShape'
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(18): error C2228: left of '.next' must have class/struct/union
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(19): error C3536: 'shape': cannot be used before it is initialized
  1&gt;c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(19): error C2227: left of '-&gt;draw' must point to class/struct/union/generic type
  1&gt;  c:\users\user\documents\laurier\fall 2016\cp411\a2_warn1700\a2_warn1700\world.cpp(19): note: type is 'int'
  1&gt;  Generating Code...
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p>LinkedList.cpp</p>
  
  <pre><code>#include "LinkedList.h"
  
  template &lt;class T&gt; void LinkedList&lt;T&gt;::insert(T* newObject) {
      if (size == 0) {
          size++;
          root = new LinkedList::Node();
          root-&gt;obj = newObject;
          lastNode = root;
          currentNode = root;
      }
      else {
          LinkedList::Node *nextNode = root;
          while (nextNode-&gt;next != nullptr) {
              nextNode = nextNode-&gt;next;
          }
          LinkedList::Node *prevNode = nextNode;
          nextNode-&gt;next = new LinkedList::Node();
          nextNode = nextNode-&gt;next;
          nextNode-&gt;prev = prevNode;
          nextNode-&gt;obj = newObject;
          lastNode = nextNode;
      }
  }
  
  template &lt;class T&gt; typename T* LinkedList&lt;T&gt;::next() {
      T* object;
      if (currentNode != nullptr) {
          object = currentNode-&gt;obj;
          currentNode = currentNode-&gt;next;
      }
      return object;
  }
  
  template &lt;class T&gt; bool LinkedList&lt;T&gt;::isNext() {
      bool moreVal = false;
      // check if there are more values
      if (currentNode != nullptr) {
          moreVal = true;
      }
      else {
          currentNode = root;
      }
      return moreVal;
  }
  
  template &lt;class T&gt; void LinkedList&lt;T&gt;::destroy() {
      Node *nextNode = root;
      while (nextNode-&gt;next != nullptr) {
          Node *temp = nextNode;
          nextNode = nextNode-&gt;next;
          delete temp;
      }
      delete root;
      delete currentNode;
      delete lastNode;
      size = 0;
      root = new Node();
      currentNode = root;
      lastNode = root;
  }
  
  template &lt;class T&gt; typename T* LinkedList&lt;T&gt;::getRoot() {
      T* object = this-&gt;root-&gt;obj;
      return object;
  }
  
  template class LinkedList&lt;Shape&gt;;
  template class LinkedList&lt;CustomShape&gt;;
  </code></pre>
  
  <p>LinkedList.h</p>
  
  <pre><code>#pragma once
  #include "Shape.h"
  #include "CustomShape.h"
  
  template &lt;class T&gt;
  class LinkedList
  {
  public:
      LinkedList&lt;T&gt;::LinkedList() {};
      LinkedList&lt;T&gt;::~LinkedList() {};
      void insert(T* newObject);
      T* next();
      bool isNext();
      void destroy();
      T* getRoot();
  private:
      struct Node {
          T* obj;
          Node* next = nullptr;
          Node* prev = nullptr;
      };
      int size = 0;
      Node *root = nullptr;
      Node *lastNode = nullptr;
      Node *currentNode = nullptr;
  };
  </code></pre>
  
  <p>World.h</p>
  
  <pre><code>#pragma once
  #include "LinkedList.h"
  #include "Shape.h"
  #include "Cube.h"
  #include "CustomShape.h"
  #include &lt;iostream&gt;
  
  class World
  {
  public:
      World();
      ~World();
      void drawWorld();
  private:
      LinkedList&lt;CustomShape&gt; worldObjects;
  };
  </code></pre>
  
  <p>World.cpp</p>
  
  <pre><code>    #include "World.h"
  
  
      World::World() {
          CustomShape* cShape = new CustomShape();
          cShape-&gt;insertShape(new Cube);
          worldObjects.insert(cShape);
      }
  
      World::~World() {
          this-&gt;worldObjects.destroy();
      }
  
      void World::drawWorld() {
          while (worldObjects.isNext()) {
              auto cShape = worldObjects.next();
              while (cShape-&gt;shapeComponents.isNext()) {
                  auto shape = cShape-&gt;shapeComponents.next();
                  shape-&gt;draw();
              }
          }
      }
  </code></pre>
  
  <p>CustomShape.h</p>
  
  <pre><code>#pragma once
  
  #include "GL\glut.h"
  #include "LinkedList.h"
  #include "Point.h"
  #include "Shape.h"
  
  class CustomShape
  {
  public:
      CustomShape();
      ~CustomShape();
      void insertShape(Shape* shape);
      LinkedList&lt;Shape&gt; shapeComponents;
      void drawSelected();
      Point originPoint;
  };
  </code></pre>
  
  <p>Thanks in advance.</p>