Title: Classes Access Specifiers
1Classes Access Specifiers
Department of Computer and Information
Science,School of Science, IUPUI
CSCI 240
Dale Roberts, Lecturer Computer Science,
IUPUI E-mail droberts_at_cs.iupui.edu
2Accessing Rights
- Private Member Functions of the Class and its
Friends - Protected Member Functions and Derived Classes
- Public Entire World
- Thumb Rule -- Data Members are Private and Member
Functions are Public
3Accessing Rights Example 1
- // date.h/ A Simple Date Class With a Proper
Accessing / define size 50 class date
private int day, month, year char
string_date public date(char ip_date)
//Constructor date() //Destructor void
print_date() //Member Function
4Accessing Rights Example 1 (cont)
- // date.cppinclude date.hdatedate(char
ip_date) day 0 month 0 year 0
string_date new char size
strcpy(string_date, ip_date) datedate()
delete (string_date) void
dateprint_date() cout ltlt "Date is " ltlt
string_date ltlt endl
5Accessing Rights Example 1 (cont)
- // client.cppinclude date.hmain() date
today("June 19, 1995") // ERROR cout ltlt
"Date is " ltlt today.string_date ltlt endl
today.print_date() //CORRECT
6Accessing Rights - Example 2
- // student.h/ A Simple Class to Represent a
Student /define size 50class Student
private char name char id char email
public Student(char , char , char
) Student() void printData()
7Accessing Rights Example 2 .
- // student.cppinclude student.h/ Member
functions of the Student" class /Student
Student(char studentName, char studentId,
char studentEmail) name new charsize
strcpy(name, studentName) id new
charsize strcpy(id, studentId) email
new charsize strcpy(email,
studentEmail)StudentStudent() delete
name delete id delete
emailvoid StudentprintData() cout ltlt
Name ltlt name ltlt endl ltlt ID ltlt id
ltlt endl ltlt Email ltlt email ltlt endl
8Accessing Rights Example 2 .
- // client.cppinclude student.h/
csStudent1" is an instance of Student"
/main() Student csStudent1 ("Susie
Creamchese, "123456789,
"screamch_at_iupui.edu") csStudent1.printData()
9Acknowledgements
- These slides were originally prepared by Rajeev
Raje, modified by Dale Roberts.