SlideShare a Scribd company logo
1 of 52
Classes and objects
5.1 C structures
• Provide method for packing different data
types together
• Handling logically related data items
• User defined data type with template that
serve to define its data properties.
• We can create variable of that type using built
in type declarations.
Example of struct
Student is the new data type and we declare variable like this
Member variable can be accessed by dot or period operator
• Structures can have arrays pointers and
structures itself as members.
• Limitations of structure
– C doesn’t allow struct datatype to be treated as
builtin data type.
– They don’t permit data hiding, can be accesed by
any function
5.2 Classes : extension of structures
• In C++ , UD data types are attempted to be treated to be
like built in data type, facility to hide data, inheritence-one
type can inherit charecteristics from other types.
• In, C++, structures can be variables& functions
• Keyword struct is omitted
• The difference between classes and structures in C++ is that
• Stuctures hold only data, and members are public-by
default
• Classes hold data and functions, members are private by
default.
5.3 specifying a class
• Class specification has 2 parts
– 1.class declaration-describes types and scope of
its members.
– 2.class function definition-describes how
functions are implemented.
The general form of class declaration is:
• Private members are accessed only within the
class, its default declaration
• Public members-outside the class also
• The variables declared inside the class are
known as data members and functions as
member function.
• Only member functions can have access to
private data members and private functions.
• The process of binding data and functions
together in a single class type variable is ref to
as encapsulation
A simple class declaration example
Getdata(), putdata() can
only be used to assign
member variables number
and cost and display
respectively.
These functions provide
the only access to data
members from outside
class.
This means that data
cannot be accessed by any
other function that is not
a member of the class
ITEM.
Creating objects
• Once class is declared we can create variables of that type. Or
even more than one variables.
Object is an instance of class.
We can also create object when class is defined by
placing immediately after closing brace as structures.
Accessing the class members
• Format for calling a member function is
Example:
Similarly
• Variable declared as public can be accessed by
objects directly.
5.4 defining member functions
Member functions can be defined in two places
– 1.outside the class definition
– 2. inside the class definition
Outside the class definition
• They are very much like normal functions.
• Should have function header and body.
• Imp difference: member function incorporates a
membership ‘identity label,(tells compiler which
class the function belong to), in the header.
example
Inside the class definition
• Another method of defining a member function is to
replace the function declaration by actual definition
inside the class.
When a function
is in a class its
treated as inline
function.
Only small
functions are
defined inside the
class definition.
5.5 C++ program with class(class implementation)
5.6 Making an outside function inline
• We can still make member function inline by
using inline in the header line of function
definition.
5.7 Nesting of member functions
• We know that member function of a class can
be called only by an object of that class using
dot operator.
• Exception: It can also be called by using its
name inside another member function of
same class.
– This is known as nesting of member functions.
5.8 private member function
• A private member function can only be called
by another function that is a member of its
class.
• Even an object cannot invoke a private
function using the dot operator.
If S1 is an object of sample then
Is illegal. However function read() can be called by function
update() to update the value of m
5.9 Arrays within a class
• Arrays can used as member variables in a
class.
The array a[] can
be used in the
member functions
like any other
variable.
We can perform
any operations on
it.
5.10 Memory allocation for objects
• Member functions are created and placed in
memory space only once when they are
defined as a part of class specification.
• No separate memory for members functions
as all objects belonging to same class use
same mem.fns.
• Separate memory locations for objects are
required as member variables will hold
different values for different objects.
5.11 Static data members
• A static member variable has certain special charecteristics:
They are used to maintain same values common to
entire class.
Eg: counter that records the occurrences of all objects.
Static variable are like inline mem.fns as they as
declared in class declaration and defined in source file.
While defining , it can be assigned initial value as well.
5.12 static member function
• A member function which is declared as static
has following properties:
– It can have access to only other static
members(fn/var) declared in the same class.
– Can be called using class name(instead of its
objects )
Example
5.13 Arrays of objects
• Arrays of variables that are of type class are
called arrays of objects.
5.14 Objects as function arguments
• An object may be used as function argument
in two ways:
– A copy of entire object is passes to the
function.(pass by value)-only copy
– Only the address of the object is transferred to the
function.(pass by reference)-here fn works directly
on the actual objects used in the call. So changes
will affect actual object- efficient
Example
An object can also be passed as argument to a non member
function.
Such fns can have access to the public member functions
only through the objects passed as arguments to it.
These functions cannot have access to the private data
members.
5.15 Friendly functions
• Wkt private functions cannot be accesed from
outside the class.
• In certain situation, C++ allows the common
function to be made friendly with both classes
, thereby allowing the function to have access
to all the private data of these classes.
• We simply declare this function as friend of
the class .
• Eg:income tax() for managers and scientist
class.
Friend function
Using friend function to add data objects of two
different classes
Shows how to use a common friend to exchange the
private values of two classes . The finction is called by
reference
5.16 returning objects
• A function can not only receive objects as
arguments but also can return them.
• The program shows how an object can be
created within the function and returned to
another function.
5.17 const member functions
• If a member function does not alter any data
in the class , then we may declare it as a const
member function.
The qualifier const is appended to function
prototypes both in declaration and definition.
The compiler will generate error message if such
functions try to alter data values.
5.18 POINTERS TO MEMBERS
Dereferencing operators
5.19 local classes

More Related Content

Similar to APL-2-classes and objects.ppt

OOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and ObjectOOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and Objectdkpawar
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Getachew Ganfur
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfismartshanker1
 
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnClass-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnYoussefSameh20
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptmanomkpsg
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptxrayanbabur
 
C++ training
C++ training C++ training
C++ training PL Sharma
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceEng Teong Cheah
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdfL1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdfBhanuJatinSingh
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsAnil Kumar
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopmShweta Shah
 

Similar to APL-2-classes and objects.ppt (20)

My c++
My c++My c++
My c++
 
OOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and ObjectOOP Unit 2 - Classes and Object
OOP Unit 2 - Classes and Object
 
Class and object
Class and objectClass and object
Class and object
 
Oops
OopsOops
Oops
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Classes-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdfClasses-and-Objects-in-C++.pdf
Classes-and-Objects-in-C++.pdf
 
Class and object
Class and objectClass and object
Class and object
 
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnClass-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
 
C++ training
C++ training C++ training
C++ training
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
L1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdfL1-Introduction to OOPs concepts.pdf
L1-Introduction to OOPs concepts.pdf
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
oopm 2.pdf
oopm 2.pdfoopm 2.pdf
oopm 2.pdf
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

APL-2-classes and objects.ppt

  • 2. 5.1 C structures • Provide method for packing different data types together • Handling logically related data items • User defined data type with template that serve to define its data properties. • We can create variable of that type using built in type declarations.
  • 3. Example of struct Student is the new data type and we declare variable like this Member variable can be accessed by dot or period operator
  • 4. • Structures can have arrays pointers and structures itself as members. • Limitations of structure – C doesn’t allow struct datatype to be treated as builtin data type. – They don’t permit data hiding, can be accesed by any function
  • 5. 5.2 Classes : extension of structures • In C++ , UD data types are attempted to be treated to be like built in data type, facility to hide data, inheritence-one type can inherit charecteristics from other types. • In, C++, structures can be variables& functions • Keyword struct is omitted • The difference between classes and structures in C++ is that • Stuctures hold only data, and members are public-by default • Classes hold data and functions, members are private by default.
  • 6. 5.3 specifying a class • Class specification has 2 parts – 1.class declaration-describes types and scope of its members. – 2.class function definition-describes how functions are implemented. The general form of class declaration is:
  • 7. • Private members are accessed only within the class, its default declaration • Public members-outside the class also • The variables declared inside the class are known as data members and functions as member function. • Only member functions can have access to private data members and private functions. • The process of binding data and functions together in a single class type variable is ref to as encapsulation
  • 8.
  • 9. A simple class declaration example Getdata(), putdata() can only be used to assign member variables number and cost and display respectively. These functions provide the only access to data members from outside class. This means that data cannot be accessed by any other function that is not a member of the class ITEM.
  • 10. Creating objects • Once class is declared we can create variables of that type. Or even more than one variables. Object is an instance of class. We can also create object when class is defined by placing immediately after closing brace as structures.
  • 11. Accessing the class members • Format for calling a member function is Example: Similarly
  • 12. • Variable declared as public can be accessed by objects directly.
  • 13. 5.4 defining member functions Member functions can be defined in two places – 1.outside the class definition – 2. inside the class definition
  • 14. Outside the class definition • They are very much like normal functions. • Should have function header and body. • Imp difference: member function incorporates a membership ‘identity label,(tells compiler which class the function belong to), in the header.
  • 16.
  • 17. Inside the class definition • Another method of defining a member function is to replace the function declaration by actual definition inside the class. When a function is in a class its treated as inline function. Only small functions are defined inside the class definition.
  • 18. 5.5 C++ program with class(class implementation)
  • 19. 5.6 Making an outside function inline • We can still make member function inline by using inline in the header line of function definition.
  • 20. 5.7 Nesting of member functions • We know that member function of a class can be called only by an object of that class using dot operator. • Exception: It can also be called by using its name inside another member function of same class. – This is known as nesting of member functions.
  • 21.
  • 22. 5.8 private member function • A private member function can only be called by another function that is a member of its class. • Even an object cannot invoke a private function using the dot operator.
  • 23. If S1 is an object of sample then Is illegal. However function read() can be called by function update() to update the value of m
  • 24. 5.9 Arrays within a class • Arrays can used as member variables in a class. The array a[] can be used in the member functions like any other variable. We can perform any operations on it.
  • 25. 5.10 Memory allocation for objects • Member functions are created and placed in memory space only once when they are defined as a part of class specification. • No separate memory for members functions as all objects belonging to same class use same mem.fns. • Separate memory locations for objects are required as member variables will hold different values for different objects.
  • 26.
  • 27. 5.11 Static data members • A static member variable has certain special charecteristics: They are used to maintain same values common to entire class. Eg: counter that records the occurrences of all objects. Static variable are like inline mem.fns as they as declared in class declaration and defined in source file. While defining , it can be assigned initial value as well.
  • 28.
  • 29. 5.12 static member function • A member function which is declared as static has following properties: – It can have access to only other static members(fn/var) declared in the same class. – Can be called using class name(instead of its objects )
  • 31. 5.13 Arrays of objects • Arrays of variables that are of type class are called arrays of objects.
  • 32. 5.14 Objects as function arguments • An object may be used as function argument in two ways: – A copy of entire object is passes to the function.(pass by value)-only copy – Only the address of the object is transferred to the function.(pass by reference)-here fn works directly on the actual objects used in the call. So changes will affect actual object- efficient
  • 34.
  • 35. An object can also be passed as argument to a non member function. Such fns can have access to the public member functions only through the objects passed as arguments to it. These functions cannot have access to the private data members.
  • 36. 5.15 Friendly functions • Wkt private functions cannot be accesed from outside the class. • In certain situation, C++ allows the common function to be made friendly with both classes , thereby allowing the function to have access to all the private data of these classes. • We simply declare this function as friend of the class . • Eg:income tax() for managers and scientist class.
  • 37.
  • 38.
  • 39.
  • 41.
  • 42. Using friend function to add data objects of two different classes
  • 43.
  • 44. Shows how to use a common friend to exchange the private values of two classes . The finction is called by reference
  • 45.
  • 46. 5.16 returning objects • A function can not only receive objects as arguments but also can return them. • The program shows how an object can be created within the function and returned to another function.
  • 47.
  • 48.
  • 49. 5.17 const member functions • If a member function does not alter any data in the class , then we may declare it as a const member function. The qualifier const is appended to function prototypes both in declaration and definition. The compiler will generate error message if such functions try to alter data values.
  • 50. 5.18 POINTERS TO MEMBERS