CIS 22B - Notes for Tuesday 3/6

Announcements and Reminders

DASB Senate

Assignment 7 - "use constructor initializers"

More Class Concepts

CIS27 Notes

Examples (zip file)

The this pointer

  • this is a pointer to the current object
  • this is most often used to return by reference
Example 5-1
Example 5-2

Static Data Members

  • A static data member is a class member that is shared among all class objects
  • It is stored in static memory, not with the rest of the class objects
  • It must be defined outside of the class, in the global workspace area
Example 5-3

Static Member Functions

  • Static member functions are used to access static data members
  • Static member functions are defined outside of the class without the keyword, static
  • Static member functions do not have access to the this pointer
Example 5-4


    • Friends are non-class member functions that have access to private members of a class
Example 5-5
Example 5-7
Example 5-8
Function Overloading, conversions

What is operator overloading?

Lab Exercise #9

Put your name, the compiler and operating system used, and Lab Exercise #9 in a comment at the top of your program. Email your source code. This lab exercise is due at the beginning of the next lecture.

Complete the following program:

class Circle
    static double Pi;
    float radius;
    Circle(float = 1.0);
    static void changePi(double);
    friend void printArea(const Circle& object);


int main()
    Circle c(5.0);

******  Program Output  ******

The area is 78.5
The area is ?