1

Possible Duplicate:
undefined reference to `WinMain@16'

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.

After compiling the Clist.cpp file, i received this error.

(.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'|

--

#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->next = this;
            if(n) next->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

--

#include "Clist.h"
#include <string.h>
#include <iostream>
using namespace std;

Clist::Clist(char d)
{
    head = new Node(d, NULL, NULL);
    head->next = head->prev = head;
    size = 1;

}
Clist::~Clist()
{

    Node *tmp = this->head;
    Node *temp;
    while(tmp->prev)
        tmp = tmp->prev;
    while(tmp)
    {

        temp = tmp->next;
        delete tmp;
        tmp = temp;
    }
    tmp = temp = NULL;

}
bool Clist::isEmpty()
{   return (this->size == 0);}

void Clist::addNodeBefore(char d)
{
    Node *n = head;
    Node *p = head->prev;

    Node *temp = new Node (d, p, n);
    size++;
    //cout << "added: " << temp->data << "  before: "
    //      << temp->prev->data << "  after: " << temp->next->data << endl;

}
void Clist::addNodeAfter(char d)
{
    Node *n = head->next;
    Node *p = head;

    Node *temp = new Node (d, p, n);
    size++;
    //cout << "added: " << temp->data << "  before: "
    //      << temp->prev->data << "  after: " << temp->next->data << endl;

}
void Clist::out(bool dir)   // True to traverse next, false to traverse prev
{
    if (dir)
    {
        Node *tmp = head;
        do{
            cout << tmp->data;
            tmp = tmp->next;
        }while(tmp != head);
    }else
    {
        Node *tmp = head;
        do{
            cout << tmp->data;
            tmp = tmp->prev;
        }while(tmp != head);
    }
    cout << endl;


}
void Clist::setData(char Data)
{
    this->head->data = Data;
}
void Clist::setPrev(Node* Prev)
{
    this->head->prev = Prev;
}
void Clist::setNext(Node* Next)
{
    this->head->next = Next;
}
bool Clist::findData(char search)
{
    int counter = 0;
    Node *tmp = head;
    while(tmp->next != head)
    {
        if(tmp->data == search)
            counter++;
        tmp = tmp->next;
    }

    if (counter > 0)
    {
        cout << "'" << search << "' was found " << counter << " time(s)" << endl;
        return true;
    }else
    {
        cout << "'" << search << "' was not found" << 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->data == search)
        {
            cout << "Deleting " << search << endl;
            tmp->prev->next = tmp->next;
            tmp->next->prev = tmp->prev;
            if (false)
                return;
        }
        tmp = tmp->next;

    }
}

--

#include <string.h>
#include <iostream>
#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 < strlen(s); i++) // create the rest of the linked list
        list->addNodeAfter(s[i]);


    list->out(true);
    list->out(false);

    cin.get();


    return 0;
}
Community
  • 1
  • 1
George
  • 337
  • 2
  • 7
  • 16
  • 1
    Check the documentation for your compiler to find out how to get it to build normal console applications. – David Schwartz Oct 07 '12 at 02:05
  • 1
    The error means that minGW cannot find your main. Which seems to be correctly declared in your code. Are you using any IDE, eclipse maybe? have you been able to run a simple program like Hello World like Beta suggested. – ForceMagic Oct 07 '12 at 03:11
  • This all used to be in one file, i split up the class into a class/header instead of being at the top of the main file. – George Oct 07 '12 at 16:37

1 Answers1

1

Since im using an IDE (Codeblocks) i tried using the project workspace. Added the class, and it works now.

George
  • 337
  • 2
  • 7
  • 16