C++, so I have this class https://www.dropbox.com/s/s3ww1xopw5b42xa/Screenshot%202015-11-30%2000.17.34.png?dl=0 can someone please explain to me what is this '&' right here: https://www.dropbox.com/s/5g2tprliy9ji466/Screenshot%202015-11-30%2000.19.11.png?dl=0 thanks
& is a pointer just a refrence
are u familiar with the top command? top() - return top item and its syntex is top(StackEntry & item) The item can be anything...or nothing. So in your case, there is nothing to return so it is blank. But the & separator must still be there. Read more from here: ftp://cseftp.tc.uvu.edu/CNS/fairclde/Fall%202009/CS%202420/Slides/chapter%2002%20Object-Oriented%20Data%20Structures.pptx
yeah i agree but in general & means a pointer. sometimes it can refer to a location what ever its type integer.. string... or whatever. tight @superdavesuper ?
@ikram002p correct - it is just "something" there available for whatever purpose. in the above linked example: ErrorCode Stack::top(StackEntry & item)const { // Pre: None // Post: If not empty, top item returned // If empty, underflow returned ErrorCode outcome = success; if(count == 0) outcome = underflow; else item = entry[count - 1]; return outcome; }//End top() So item is used to store the previous entry. if necessary...
so if I just leave it like this (&) (not &item) will it compile ? also what's that pre and post ?????
thanks a lot for answering to me
@Christos it will compile just fine. sorry i didnt see any pre or post in ur codes.
I know there weren't , I am just asking cause I see that a lot // Pre: None // Post: .....
sorry i cant tell w/o seeing the codes...
here is the code
ErrorCode Stack::top(StackEntry & item)const { // Pre: None // Post: If not empty, top item returned // If empty, underflow returned ErrorCode outcome = success; if(count == 0) outcome = underflow; else item = entry[count - 1]; return outcome; }//End top() So item is used to store the previous entry. if necessary...
Oh @Christos i just cut & paste from the example n didnt remember wats in there lol
That whole section: // Pre: None // Post: If not empty, top item returned // If empty, underflow returned contains just comments and explains how the stacks operate ;)
Nice slides!!!
pre means before and post means after
yup yup @Christos
thanks
Join our real-time social learning platform and learn together with your friends!