Download presentation
Presentation is loading. Please wait.
Published bySybil Cummings Modified over 9 years ago
1
CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008
2
Functions Same as in java but: –Can be defined outside of any class. –Can use default parameters int max(int a = 0, int b = 0); –Parameters after those given a default value must also be default. –Inline functions Rather than jump at run-time, paste in at compile time –inline int max(int a, int b) { return a > b ? a : b; } –More versatile parameter passing.
3
Parameter passing Call by value – typical Java way. –void swap (int a, int b); Call by reference – can change actual parameters –void swap (int &a, int &b); Call by const reference – function promises not to change actual parameter –int binSearch(const vector &arr, int key); Arrays passed by reference, but vectors passed by value (default).
4
Templates, Generics Lab.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.