comparing stacks

Oct 23, 2008 at 6:44pm
How do you overload the == operator in a stack?
Oct 23, 2008 at 6:55pm
I would imagine, the same way you override all other operators. But making sure it's a global operator the same as the original ==. The question is, why would you want to override it?
Oct 23, 2008 at 7:15pm
i need to be able to see if stack1 == stack2
Last edited on Oct 23, 2008 at 7:20pm
Oct 23, 2008 at 7:23pm
There is already an operator for this.
Oct 23, 2008 at 7:35pm
yes but the assignment asks for me to overload the == operator so that i can compare 2 stacks
Oct 23, 2008 at 7:37pm
1
2
3
bool operator==(const stack&, const stack&) {

}
Oct 23, 2008 at 7:40pm
lol i know how to overload the == operator in a general program, but you need templates in a stack and you cant overload the == the same way

i need to be able to compare stack1 (which contains 1,2,3) to stack2 (which contains 2,3,4,5) and so on
Oct 23, 2008 at 7:47pm
Surely you could've figured it out. It's just the same.

1
2
3
4
template<typename T>
bool operator==(const stack<T>& stack1, const stack<T>& stack2) {
  return false;
}
Oct 23, 2008 at 7:52pm
yeah i have the syntax figured out, im just having trouble writing the definition.
i cant seem to figure out how to compare the size of the stack and the elements of the stack
Oct 23, 2008 at 7:56pm
Oct 23, 2008 at 8:09pm
neither of those showed me how to define the the function
Oct 23, 2008 at 8:29pm
That's what your suppose to come up with yourself. We aren't here to give you answers to your homework.
Oct 23, 2008 at 9:05pm
my professor instructed us to go online and look for how to do it
Oct 23, 2008 at 9:13pm
Then start digging through the source code to your compiler's STL. Have a look at how it's done there.
Topic archived. No new replies allowed.