N
Neila
I have the following classes
a Class Stack that holds the class ListNode( what the program does is that
it simulates the stack using a linked list). As it is now it works
perfectly, however what I want to do is to move the ListNode class outside
my Stack class.
Current implementation is aas follows:
template <class Object>
class Stack
{
public:
Stack( );
Stack( const Stack & rhs );
~Stack( );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
const Stack & operator=( const Stack & rhs );
private:
class ListNode
{
public:
ListNode( const Object & theElement, ListNode * n = NULL )
: element( theElement ), next( n ) { }
Object element;
ListNode *next;
};
ListNode* topOfStack;
};
This is what I'm trying to do but my compiler tells me there is an error
"syntax error before `*'" (I commented the line // <- !!!!!!!! ERROR
HERE!!!!!!!!!!! so you can easily find it). Do I need to somehow instanciate
the NodeClass in the private section of Stack class in order to use it ? Any
help would be much appreciated thanks
template <class Object>
class ListNode
{
public:
ListNode( const Object & theElement, ListNode * n = NULL )
: element( theElement ), next( n ) { }
Object element;
ListNode *next;
};
template <class Object>
class Stack
{
public:
Stack( );
Stack( const Stack & rhs );
~Stack( );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
const Stack & operator=( const Stack & rhs );
private:
ListNode* topOfStack; // <- !!!!!!!! ERROR HERE!!!!!!!!!!!
};
a Class Stack that holds the class ListNode( what the program does is that
it simulates the stack using a linked list). As it is now it works
perfectly, however what I want to do is to move the ListNode class outside
my Stack class.
Current implementation is aas follows:
template <class Object>
class Stack
{
public:
Stack( );
Stack( const Stack & rhs );
~Stack( );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
const Stack & operator=( const Stack & rhs );
private:
class ListNode
{
public:
ListNode( const Object & theElement, ListNode * n = NULL )
: element( theElement ), next( n ) { }
Object element;
ListNode *next;
};
ListNode* topOfStack;
};
This is what I'm trying to do but my compiler tells me there is an error
"syntax error before `*'" (I commented the line // <- !!!!!!!! ERROR
HERE!!!!!!!!!!! so you can easily find it). Do I need to somehow instanciate
the NodeClass in the private section of Stack class in order to use it ? Any
help would be much appreciated thanks
template <class Object>
class ListNode
{
public:
ListNode( const Object & theElement, ListNode * n = NULL )
: element( theElement ), next( n ) { }
Object element;
ListNode *next;
};
template <class Object>
class Stack
{
public:
Stack( );
Stack( const Stack & rhs );
~Stack( );
bool isEmpty( ) const;
bool isFull( ) const;
const Object & top( ) const;
void makeEmpty( );
void pop( );
void push( const Object & x );
Object topAndPop( );
const Stack & operator=( const Stack & rhs );
private:
ListNode* topOfStack; // <- !!!!!!!! ERROR HERE!!!!!!!!!!!
};