I'm trying to build a stack class. Bascailly it consists of the following files:
Code:// listnode.h #ifndef LISTNODE_H #define LISTNODE_H class ListNode { public: int data; // stores the integer ListNode *next; // pointer to next ListNode }; #endifCode:// stack.h #ifndef STACK_H #define STACK_H #include "listnode.h" class Stack { public: Stack(); // constructor ~Stack(); // destructor int pop(); // remove top item in stack void push(int); // add item to stack int top(); // return item from top of stack void print(); // print contents of stack bool isEmpty(); private: ListNode *topNode; // top listnode in list }; #endifWhen I compile a file called stacktest.cpp I get the following error:Code:// stack.cpp #include <iostream> using std::cout; #include "stack.h" // constructor Stack::Stack() { topNode = NULL; } // destructor Stack::~Stack() { delete topNode; } void Stack::push(int item) { ListNode *node = new ListNode(); node->data = item; node->next = topNode; topNode = node; } int Stack::pop() { assert(topNode != NULL); int temp = topNode->data; topNode = topNode->next; return temp; } void Stack::print() { ListNode *node = topNode; while(node != NULL) { cout << node->data << ' '; } if(node == NULL) cout << "Stack is empty!"; } .. etc
That file basically looks as follows:stacktest.cpp request for member `print' in `testStack', which is of non-class type `Stack ()()'
Any ideas as to what I've done incorrectly?Code:// stackTest.cpp #include <iostream> using std::cout; using std::cin; #include "stack.h" int main() { Stack testStack(); testStack.print(); cin.get(); return 0; }



LinkBack URL
About LinkBacks



rint()'