Class constant question

Hello !

i study about stacks. i find that

bool stack::top(double &item) const;
the parameter that is pass here is output parameter

bool stack::push(const double &item);
the parameter that is pass here is input parameter

My question is, what is the difference of those 2?
The first syntax means no data members will be modified by the function, and that the parameter can (and, considering const correctness, will) be modified.

The second one ensures the parameter won't be modified, and that data members might be (again, if it's const correct, one or more of them will be modified).
Last edited on
Thanks filipe, i can combine both also ?
bool stack::push(const double &item) const;
You can combine both but not likely in the stack::push() function. Pushing onto a stack must modify the stack object and therefore the function that pushes items onto the stack could not be declared const.
Yeah, i understand! Thanks Galik!. I found stacks very interesting.
Topic archived. No new replies allowed.