Pls comment for further improvements...

Ive written a stack class.Heres the code: http://paste.debian.net/417593/
And main.cpp: http://paste.debian.net/417592/

I hav received various suggestions from Moschops and others.Pls help me in giving more suggestions guys.Ill use it in a program for a Mathematical parserr.
You are throwing and catching exceptions within the same function, just to output to cerr. Why bother?

Replace throw 3; with std::cerr<< "Tried to delete top of the Stack,which is a nullptr !!!\n"; and similarly for others.
So,i shouldnt include the nested class into the Stack class,ok.
Thnx Moschops!
Heres the errors corrected: http://paste.debian.net/417617/
You are throwing and catching exceptions within the same function, just to output to cerr. Why bother?

Replace throw "Tried to delete top of the Stack,which is a nullptr !!!\n"; with std::cerr<< "Tried to delete top of the Stack,which is a nullptr !!!\n"; and similarly for others.
Normally you throw exceptions in the code that has to report an error it can't handle. You catch an exception when you can deal with the error.

Stack :: ~Stack()
Why would you want to throw an exception here. An empty stack is not an error.
void Stack :: pop()
Trying to pop an empty stack is definitely an error and should be reported to the caller.
void Stack :: push(int &a)
How can yo actually get an stack overflow? If there is not enough memory you will get an bad_alloc exception from new
1
2
3
4
node *RET_topnode()
    {
	return top;
    }

Why don't you return the value instead of a node?
Topic archived. No new replies allowed.