[Dev-C++] undefined reference error?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Zachary U. <ne...@st...> - 2002-12-14 08:13:43
|
Hi,
I created empty project, I added 2 files to it: stack.h and stack.cpp
When I compile I get weird error. It is very obtuse and does not even give
a Line number of the error! Here is error:
Compiler: Default compiler
Building Makefile: "C:\c++\PSCpp4E\ch15\Makefile.win"
Executing make...
make.exe -f "C:\c++\PSCpp4E\ch15\Makefile.win" all
g++.exe -c stack.cpp -o stack.o
-I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include"
g++.exe stack.o -o "Stack.exe"
-L"C:/DEV-CPP/lib" -I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include"
C:/DEV-CPP/lib/libmingw32.a(main.o)(.text+0x7f):main.c: undefined reference
to `WinMain@16'
Execution terminated
Please help someone.
Below are source files.
Regards,
Zach
//This is the header file stack.h. This is the interface for the class Stack,
//which is a class for a stack of symbols.
#ifndef STACK_H
#define STACK_H
namespace stacksavitch
{
struct StackFrame
{
char data;
StackFrame *link;
};
typedef StackFrame* StackFramePtr;
class Stack
{
public:
Stack( );
//Initializes the object to an empty stack.
Stack(const Stack& a_stack);
//Copy constructor.
~Stack( );
//Destroys the stack and returns all the memory to the freestore.
void push(char the_symbol);
//Postcondition: the_symbol has been added to the stack.
char pop( );
//Precondition: The stack is not empty.
//Returns the top symbol on the stack and removes that
//top symbol from the stack.
bool empty( ) const;
//Returns true if the stack is empty. Returns false otherwise.
private:
StackFramePtr top;
};
}//stacksavitch
#endif //STACK_H
//This is the implementation file stack.cpp.
//This is the implementation of the class Stack.
//The interface for the class Stack is in the header file stack.h.
#include <iostream>
#include <cstddef>
#include "stack.h"
using namespace std;
namespace stacksavitch
{
//Uses cstddef:
Stack::Stack( ) : top(NULL)
{
//Body intentionally empty.
}
//Uses cstddef:
Stack::Stack(const Stack& a_stack)
{
if (a_stack.top == NULL)
top = NULL;
else
{
StackFramePtr temp = a_stack.top;//temp moves
//through the nodes from top to bottom of
//a_stack.
StackFramePtr end;//Points to end of the new stack.
end = new StackFrame;
end->data = temp->data;
top = end;
//First node created and filled with data.
//New nodes are now added AFTER this first node.
temp = temp->link;
while (temp != NULL)
{
end->link = new StackFrame;
end = end->link;
end->data = temp->data;
temp = temp->link;
}
end->link = NULL;
}
}
Stack::~Stack( )
{
char next;
while (! empty( ))
next = pop( );//pop calls delete.
}
//Uses cstddef:
bool Stack::empty( ) const
{
return (top == NULL);
}
//Uses cstddef:
void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}
//Uses iostream:
char Stack::pop( )
{
if (empty( ))
{
cout << "Error: popping an empty stack.\n";
exit(1);
}
char result = top->data;
StackFramePtr temp_ptr;
temp_ptr = top;
top = top->link;
delete temp_ptr;
return result;
}
}//stacksavitch
Zachary Uram
John 3:16
<><
|