cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : General C++ Programming : comparing stacks
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  comparing stacks

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

}
|
ironman (20)
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
|
Zaita (1560)
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;
}
|
ironman (20)
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
|
Zaita (1560)
http://www.sgi.com/tech/stl/stack.html
http://www.sgi.com/tech/stl/Container.html
|
ironman (20)
neither of those showed me how to define the the function
|
Zaita (1560)
That's what your suppose to come up with yourself. We aren't here to give you answers to your homework.
|
ironman (20)
my professor instructed us to go online and look for how to do it
|
Zaita (1560)
Then start digging through the source code to your compiler's STL. Have a look at how it's done there.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us