IUPUI CS 265 - Classes (32 pages)

Previewing pages 1, 2, 15, 16, 31, 32 of 32 page document View the full content.
View Full Document

Classes



Previewing pages 1, 2, 15, 16, 31, 32 of actual document.

View the full content.
View Full Document
View Full Document

Classes

112 views

Lecture Notes


Pages:
32
School:
Indiana University - Purdue University Indianapolis
Course:
Cs 265 - Advanced Programming

Unformatted text preview:

Department of Computer and Information Science School of Science IUPUI CSCI 265 Classes Part 2 Dale Roberts Lecturer Computer Science IUPUI E mail droberts cs iupui edu 01 14 19 Dale Roberts 1 Friend Function Example define size 50 class student char name public student char ip name new char size strcpy name ip print cout Name name endl friend function friend void dangerous fn student 01 14 19 Dale Roberts 2 Friend Function Example void dangerous fn student s strcpy s name DANGER main student s1 John s1 print dangerous fn s1 s1 print OUTPUT WILL BE Name John Name DANGER 01 14 19 Dale Roberts 3 Friend Classes Danger Not Directly Associated with the Class All the Member Functions of the Friend Class Can Access Non Public Data Members of the Original Class Can be Friend of More than One Classes Violation of Encapsulation SHOULD BE USED ONLY WHEN REQUIRED 01 14 19 Dale Roberts 4 Friend Class Example define size 50 class student char name public student char ip name new char size strcpy name ip print cout Name name endl friend class friend class dummy 01 14 19 Dale Roberts 5 Friend Class Example class dummy Friend Class public void danger member fn student s strcpy s name FRIEND or FOE main student s John s print dummy risk risk danger member fn s s print OUTPUT WILL BE Name John Name FRIEND or FOE 01 14 19 Dale Roberts 6 Class Objects as Members Data Members are of User Defined Types Having their Constructors Constructor Initializer is Used Appropriate Constructors are Invoked on the Order they are Specified in the Class Declaration Destructor of the Class Containing Members of Other Classes is Called First Followed by the Member s Destructors in Reverse Order of Declaration 01 14 19 Dale Roberts 7 Class Objects as Members Example class student char name public student char ip name new char 50 strcpy name ip student delete name 01 14 19 Dale Roberts 8 Class Objects as Members Example class instructor char name public instructor char ip name new char 50 strcpy name ip



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Classes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?