CIS 22B - Notes for Monday 11/19

Announcements and Reminders

Today's Lecture Recording is here => https://cccconfer.zoom.us/recording/share/vkMZtAChv6w5faEqkt7i74PWFViA1g8TNyiXbW0K3TiwIumekTziMw


More Class Concepts

CIS27 Notes

Examples (zip file)

enums and classes

Nested classes

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

    • 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;
public:
    Circle(float = 5.0);
    static void changePi(double);
    friend void displayArea(const Circle& object);
};


???

int main()
{
    Circle c(10.0);
    displayArea(c);
    Circle::changePi(3.1416);
    displayArea(c);
}


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

The area is 314
The area is ?