1 / 7

Class 2: Functions

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

helen
Download Presentation

Class 2: Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 2: Functions

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

More Related