title: C++ Linked List Class -> header file
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16">undefined reference to `WinMain@16&#39;</a>  </p>
  </blockquote>
  
  
  
  <p>Ive been working on a circular, double linked list. Decided to create a class and use a header. I'm new to C++ so i checked to see how to implement it. I'm not sure if i correctly implemented the struct node within the list.</p>
  
  <p>After compiling the Clist.cpp file, i received this error.     </p>
  
  <pre><code>(.text+0xd2): undefined reference to `WinMain@16'
  collect2: ld returned 1 exit status
  Process terminated with status 1 (0 minutes, 1 seconds)
  1 errors, 0 warnings
  d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'|
  </code></pre>
  
  <p>--</p>
  
  <pre><code>#ifndef CLIST_H
  #define CLIST_H
  struct  Node {
          char data;
          Node *prev, *next;
          Node (char d, Node *p, Node *n): data(d), prev(p), next(n)
          {
              if(p) prev-&gt;next = this;
              if(n) next-&gt;prev = this;
          }
  };
  
  class Clist
  {
      public:
          Clist(char);
          virtual ~Clist();
          Node *head;     // current node that is being pointed to
          int size;
          bool isEmpty();
          void addNodeBefore(char);           // inserted before head
          void addNodeAfter(char);            // inserted after head
          void addNodeBeforeData(char, Node*);// Same as above, inserted before/after a specific node
          void addNodeAfterData(char, Node*);
          void out(bool);     // Prints the list, true starts from beginning, false starts from end
          void setData(char);
          void setPrev(Node*);
          void setNext(Node*);
          bool findData(char);    // Searches through the list to find the char
          void deleteData(char, bool);
  
  };
  
  #endif // CLIST_H
  </code></pre>
  
  <p>--</p>
  
  <pre><code>#include "Clist.h"
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  Clist::Clist(char d)
  {
      head = new Node(d, NULL, NULL);
      head-&gt;next = head-&gt;prev = head;
      size = 1;
  
  }
  Clist::~Clist()
  {
  
      Node *tmp = this-&gt;head;
      Node *temp;
      while(tmp-&gt;prev)
          tmp = tmp-&gt;prev;
      while(tmp)
      {
  
          temp = tmp-&gt;next;
          delete tmp;
          tmp = temp;
      }
      tmp = temp = NULL;
  
  }
  bool Clist::isEmpty()
  {   return (this-&gt;size == 0);}
  
  void Clist::addNodeBefore(char d)
  {
      Node *n = head;
      Node *p = head-&gt;prev;
  
      Node *temp = new Node (d, p, n);
      size++;
      //cout &lt;&lt; "added: " &lt;&lt; temp-&gt;data &lt;&lt; "  before: "
      //      &lt;&lt; temp-&gt;prev-&gt;data &lt;&lt; "  after: " &lt;&lt; temp-&gt;next-&gt;data &lt;&lt; endl;
  
  }
  void Clist::addNodeAfter(char d)
  {
      Node *n = head-&gt;next;
      Node *p = head;
  
      Node *temp = new Node (d, p, n);
      size++;
      //cout &lt;&lt; "added: " &lt;&lt; temp-&gt;data &lt;&lt; "  before: "
      //      &lt;&lt; temp-&gt;prev-&gt;data &lt;&lt; "  after: " &lt;&lt; temp-&gt;next-&gt;data &lt;&lt; endl;
  
  }
  void Clist::out(bool dir)   // True to traverse next, false to traverse prev
  {
      if (dir)
      {
          Node *tmp = head;
          do{
              cout &lt;&lt; tmp-&gt;data;
              tmp = tmp-&gt;next;
          }while(tmp != head);
      }else
      {
          Node *tmp = head;
          do{
              cout &lt;&lt; tmp-&gt;data;
              tmp = tmp-&gt;prev;
          }while(tmp != head);
      }
      cout &lt;&lt; endl;
  
  
  }
  void Clist::setData(char Data)
  {
      this-&gt;head-&gt;data = Data;
  }
  void Clist::setPrev(Node* Prev)
  {
      this-&gt;head-&gt;prev = Prev;
  }
  void Clist::setNext(Node* Next)
  {
      this-&gt;head-&gt;next = Next;
  }
  bool Clist::findData(char search)
  {
      int counter = 0;
      Node *tmp = head;
      while(tmp-&gt;next != head)
      {
          if(tmp-&gt;data == search)
              counter++;
          tmp = tmp-&gt;next;
      }
  
      if (counter &gt; 0)
      {
          cout &lt;&lt; "'" &lt;&lt; search &lt;&lt; "' was found " &lt;&lt; counter &lt;&lt; " time(s)" &lt;&lt; endl;
          return true;
      }else
      {
          cout &lt;&lt; "'" &lt;&lt; search &lt;&lt; "' was not found" &lt;&lt; endl;
          return false;
      }
  }
  
  void Clist::deleteData(char search, bool all)   // If true, it will delete all nodes with the same search
  {                                               // If false, it will delete the first Node only
      Node *tmp = head;
      while(tmp)
      {
          if(tmp-&gt;data == search)
          {
              cout &lt;&lt; "Deleting " &lt;&lt; search &lt;&lt; endl;
              tmp-&gt;prev-&gt;next = tmp-&gt;next;
              tmp-&gt;next-&gt;prev = tmp-&gt;prev;
              if (false)
                  return;
          }
          tmp = tmp-&gt;next;
  
      }
  }
  </code></pre>
  
  <p>--</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;iostream&gt;
  #include "Clist.h"
  using namespace std;
  
  
  
  int main(int argc, char* argv[])
  {
  
  
      char s[]="abcfdefghijklmgnopqrsatuvwxyz";
  
      Clist *list; // ptr to head of list
      Node *curr; // ptr to current node of the list
  
      // call constructor and initialize first Node
      list = new Clist(s[0]);
  
      for(size_t i=1; i &lt; strlen(s); i++) // create the rest of the linked list
          list-&gt;addNodeAfter(s[i]);
  
  
      list-&gt;out(true);
      list-&gt;out(false);
  
      cin.get();
  
  
      return 0;
  }
  </code></pre>