Class division

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!!!!!!!!!!!

};
 
V

Victor Bazarov

Neila said:
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!!!!!!!!!!!

Should be
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top