70 likes | 188 Vues
This resource covers crucial concepts in function implementation for CIS 601, including the importance of the 'skeleton' in maintaining type-safe computing. It discusses where and when to apply const, member functions, and how to handle class friendships to control access to private data. You'll learn about function overloading with different signatures and the necessity of using common sense when naming overloaded functions. This guide serves as a foundation for building robust and secure code practices.
E N D
Next week • For Sept 27 • Page 102, 3.10.2 (1) Playing cards • Page 103, 3.10.3(1) Employee Class CIS 601 Fall 02
Function prototype • What: the ‘skeleton’ • Why: (type) safe computing • When: always (even when not required) • Where: at top of .cpp file • Note: .h (header) file takes care of this for a class CIS 601 Fall 02
const • Only with & • What would void func(const int aVar) mean? • A function may be const • Never return a non-const reference to private dataprivData & func(int aVar); CIS 601 Fall 02
this • Pointer (address) of current object • Only permitted in member function • obj & Obj::echo(Obj anObj){ return *this;} • * dereferences this • & and * are inverses of each other CIS 601 Fall 02
friend • friend classes get access to private information • You get to decide who your friends are • class ClassA{ friend ClassB;} • Friendship is not transitive. (A friend of a friend is not a friend.) CIS 601 Fall 02
Overloading • Different functions, same name • Must have different signatures (Note: Type difference is not enough) • Use common sense: overloaded names should do similar things! • Often overload constructors CIS 601 Fall 02