title: Compiler says every constructor and function is being redefined and won't compile. Am I using the #IFNDEF wrong? - C++
body: <p>I am trying to implement my own OrderedList data structure using class templates. Each constructor and function in my CPP file has an error on the opening '{'. The error reads "redefinition of FUNCTION_NAME   FUNTION_NAME previously declared here".</p>
  
  <p>I've had a few colleagues look at it, but to no avail. Here are my files and the error:</p>
  
  <p><strong>CPP FILE "MyOrderedList.cpp"</strong></p>
  
  <pre><code>#include "MyOrderedList.h"
  
  template &lt;class E&gt;
  MyOrderedList&lt;E&gt;::MyOrderedList() {/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  MyOrderedList&lt;E&gt;::MyOrderedList(const MyOrderedList&lt;E&gt;&amp; orig) { /*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  void MyOrderedList&lt;E&gt;::operator =(const MyOrderedList&lt;E&gt;&amp; orig){/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  MyOrderedList&lt;E&gt;::~MyOrderedList() {/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  void MyOrderedList&lt;E&gt;::insert(E data){/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  E MyOrderedList&lt;E&gt;::get(int pos) const{/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  Node&lt;E&gt;* MyOrderedList&lt;E&gt;::getHead() const{/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::kLargest(int k) const{/*IMPLEMENTATION*/}
  
  template &lt;class E&gt;
  MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::operator +(const MyOrderedList&lt;E&gt;&amp; list {/*IMPLEMENTATION*/}
  </code></pre>
  
  <p><strong>H FILE "MyOrderedList.h"</strong></p>
  
  <pre><code>#ifndef MYORDEREDLIST_H
  #define MYORDEREDLIST_H
  
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include "Node.h"
  
  template &lt;class E&gt;
  class MyOrderedList;
  template &lt;class E&gt;
  std::ostream&amp; operator &lt;&lt;(std::ostream&amp; out, const MyOrderedList&lt;E&gt;&amp; list);
  
  template &lt;class E&gt;
  class MyOrderedList {
  public:
      MyOrderedList();
      MyOrderedList(const MyOrderedList&lt;E&gt;&amp; orig);
      void operator =(const MyOrderedList&lt;E&gt;&amp; orig);
      virtual ~MyOrderedList();
  
      bool remove(E data);
      MyOrderedList&lt;E&gt; kLargest(int k) const;
      E get(int pos) const;
      void insert(E data);
      Node&lt;E&gt;* getHead() const;
  
      MyOrderedList&lt;E&gt; operator +(const MyOrderedList&lt;E&gt;&amp; list);
  
      friend std::ostream&amp; operator &lt;&lt;(std::ostream&amp; out, const MyOrderedList&lt;E&gt;&amp; list){/*IMPLEMENTATION*/}
  
  private:
      Node&lt;E&gt;* head;
      int size;
  };
  
  #include "MyOrderedList.cpp"
  #endif  //MYORDEREDLIST_H
  </code></pre>
  
  <p><strong>Node.h</strong></p>
  
  <pre><code>#ifndef NODE_H
  #define NODE_H
  
  #include &lt;iostream&gt;
  
  template &lt;class E&gt;
  class Node {
  public:
      Node(const E&amp; init_data = NULL, Node&lt;E&gt;* init_link = NULL){data = init_data; link = init_link;}
      Node(const Node&lt;E&gt;&amp; orig);
      virtual ~Node();
  
      E getData() const{return data;}
      void setData(E newData);
  
      Node&lt;E&gt;* getLink(){return link;}
      void setLink(Node&lt;E&gt;* nextLink) {link = nextLink;}
  private:
      E data;
      Node&lt;E&gt;* link;
  };
  
  #endif  /* NODE_H */
  </code></pre>
  
  <p><strong>Compiler Errors</strong></p>
  
  <pre><code>MyOrderedList.cpp:12: error: redefinition of `MyOrderedList&lt;E&gt;::MyOrderedList()'
  MyOrderedList.cpp:12: error: `MyOrderedList&lt;E&gt;::MyOrderedList()' previously declared here
  MyOrderedList.cpp:19: error: redefinition of `MyOrderedList&lt;E&gt;::MyOrderedList(const MyOrderedList&lt;E&gt;&amp;)'
  MyOrderedList.cpp:19: error: `MyOrderedList&lt;E&gt;::MyOrderedList(const MyOrderedList&lt;E&gt;&amp;)' previously declared here
  MyOrderedList.cpp:42: error: redefinition of `void MyOrderedList&lt;E&gt;::operator=(const MyOrderedList&lt;E&gt;&amp;)'
  MyOrderedList.cpp:42: error: `void MyOrderedList&lt;E&gt;::operator=(const MyOrderedList&lt;E&gt;&amp;)' previously declared here
  MyOrderedList.cpp:77: error: redefinition of `MyOrderedList&lt;E&gt;::~MyOrderedList()'
  MyOrderedList.cpp:77: error: `virtual MyOrderedList&lt;E&gt;::~MyOrderedList()' previously declared here
  MyOrderedList.cpp:91: error: redefinition of `void MyOrderedList&lt;E&gt;::insert(E)'
  MyOrderedList.cpp:91: error: `void MyOrderedList&lt;E&gt;::insert(E)' previously declared here
  MyOrderedList.cpp:119: error: redefinition of `E MyOrderedList&lt;E&gt;::get(int) const'
  MyOrderedList.cpp:119: error: `E MyOrderedList&lt;E&gt;::get(int) const' previously declared here
  MyOrderedList.cpp:134: error: redefinition of `Node&lt;E&gt;* MyOrderedList&lt;E&gt;::getHead() const'
  MyOrderedList.cpp:134: error: `Node&lt;E&gt;* MyOrderedList&lt;E&gt;::getHead() const' previously declared here
  MyOrderedList.cpp:140: error: redefinition of `MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::kLargest(int) const'
  MyOrderedList.cpp:140: error: `MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::kLargest(int) const' previously declared here
  MyOrderedList.cpp:158: error: redefinition of `MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::operator+(const MyOrderedList&lt;E&gt;&amp;)'
  MyOrderedList.cpp:158: error: `MyOrderedList&lt;E&gt; MyOrderedList&lt;E&gt;::operator+(const MyOrderedList&lt;E&gt;&amp;)' previously declared here
  </code></pre>