70 likes | 180 Views
Class 2: Functions. Next week. For Sept 27 Page 102, 3.10.2 (1) Playing cards Page 103, 3.10.3(1) Employee Class. Function prototype. What: the ‘skeleton’ Why: (type) safe computing When: always (even when not required) Where: at top of .cpp file
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