Link to home
Start Free TrialLog in
Avatar of archytas
archytas

asked on

Calcuations on Object?s

Hey all.

I need to use a stack to do postfix calculations. Heres the problem -- when you pop from the stack its automatically an Object but you cant perform adding, and so on, on Objects??

Any Idea's? I can show the code if anyone wants?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Venci75
Venci75

your objects could contain the type of the value and perform the appropriate '+' operation depending on that type
casting the object to the type that you want ..
int or double most prob ..

den just add to a total variable

int total;
total += (int) stack.pop();
>>int or double most prob ..

How can an object be cast to an int?
>total += (int) stack.pop();

Can't do that :-)
first of all, how are u pushing your values into the stack? You must be casting them into some Object type, right?

when u pop them do the same casting.

vemul
archytas:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer
Avatar of archytas

ASKER

Hey folks,

Sorry I didn't get back to u on this one. Solved it afterall.

Thanks all