By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Class division

P: n/a
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!!!!!!!!!!!

};

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Neila" <mo**@nospam.com> wrote...
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

ListNode<Object>* topOfStack;

};

Jul 22 '05 #2

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:1IQBb.495399$HS4.3824960@attbi_s01...
ListNode<Object>* topOfStack;

Thanks alot
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.