comparing stacks

How do you overload the == operator in a stack?
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?
i need to be able to see if stack1 == stack2
Last edited on
There is already an operator for this.
yes but the assignment asks for me to overload the == operator so that i can compare 2 stacks
1
2
3
bool operator==(const stack&, const stack&) {

}
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
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;
}
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
neither of those showed me how to define the the function
That's what your suppose to come up with yourself. We aren't here to give you answers to your homework.
my professor instructed us to go online and look for how to do it
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.