Yeah, I'm having mad trouble getting my code to work together...
when I compile this cpp file:
Code:
#include <stdlib.h>
#include <iostream.h>
#include "Stack.h"
struct StackNode
{
int entry;
StackNode *next;
};
Stack::Stack ()
{
counter = 0;
top = NULL; //<---Here is where error two occurs
}
void Stack :: push(int data)
{
StackNode temp;
temp.entry = data;
temp.next = top;
*top = temp;
}
int Stack :: pop()
{
int dataHolder;
dataHolder = top -> entry;
top = top -> next;
return dataHolder;
}
bool Stack :: IsEmpty()
{
return (top == NULL);
}
int Stack :: peek()
{
return top -> entry;
}
void Stack :: test()
{
cout << "test";
}
with this header:
Code:
/* Stack.h - Stack Specification */
#include <stdlib.h>
#ifndef STACK_H
#define STACK_H
class Stack
{
public:
Stack();
void push(int data);
int pop();
int peek();
bool IsEmpty();
void test();
private:
StackNode *top; //<<---here is where error
int counter; // one occurs
};
#endif
I get these errors:
Stack.h:17: syntax error before `*'
Stack.cpp: In method `Stack::Stack()':
Stack.cpp:36: `top' undeclared (first use this function)
Stack.cpp:36: (Each undeclared identifier is reported only once
Stack.cpp:36: for each function it appears in.)
Nwhen I include the class definition in the cpp file, I get no errors, other than the fact that I don't have a main routine.
Please help, as I have NOBODY around to help me out with this.
Thanks.