473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Class division

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
2 1277
"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
5
by: Laszlo Zsolt Nagy | last post by:
Hughes, Chad O wrote: > Is there any way to create a class method? I can create a class > variable like this: > Hmm, seeing this post, I have decided to implement a 'classproperty'...
4
by: tajmorton | last post by:
Hello, I've decided to try my hand at writing a decimal class that is suitable for storing weights, money, and time, etc, because I haven't found a *decimal* class (yes, I know that boost and gmp...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
2
by: kermit | last post by:
For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the...
7
by: eggie5 | last post by:
I have multiple elements with the same class ID. I want to Hide them all, but I only know how to select one element at a time, e.g. Element.hide('element). How can I do this to multiple elements...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
10
by: =?iso-8859-2?B?SmFuIFJpbmdvuQ==?= | last post by:
Hello everybody, this is my first post to a newsgroup at all. I would like to get some feedback on one proposal I am thinking about: --- begin of proposal --- Proposal to add...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.