SlideShare a Scribd company logo
Data Member
and
Member Function
MADE BY:
HARSH PATEL :140950107057
DRASHTI PATEL :140950107056
CSE-B
Class Specification
• Syntax:
class class_name
{
};
Data members
Members functions
Class Specification
• Visibility of Data members & Member functions
public - accessed by member functions and all
other non-member functions in the
program.
private - accessed by only member functions of the
class.
protected - similar to private, but accessed by
all the member functions of
immediate derived class
default - all items defined in the class are private.
Data Members
• The variables declared inside the class are
known as data members.
• The private data of a class can be accessed
only through the member functions of that
class.
• Data members Can be of any type, built-in or
user-defined
Accessing Data Members
(inside the class)
• Syntax: (single object)
data_member;
ex: st_id;
• Syntax:(array of objects)
data_member;
ex: st_id;
Accessing Data Members
(outside the class)
• Syntax: (single object)
obj_name . datamember;
ex: st.st_id;
• Syntax:(array of objects)
obj_name[i] . datamember;
ex: st[i].st_id;
Member Function
• The functions declared inside the class are
known as member functions.
• Member functions access the values of the
data members and perform operations on the
data members .
• Their definition can be placed inside the class
body, or outside the class body.
• Can access both public and private members
of the class
Defining Member Functions
• Member functions can be defined in two
places:
– Inside the class definition.
– Outside the class definition.
Defining Member Functions
• Inside the Class Definition
– Replace the function declaration with the
definition of the function inside the class.
– When a function is defined inside a class, it is
treated as an inline function.
– All the restrictions and limitations that apply
to an inline function are also applicable to the
functions defined inside a class.
Defining Member Functions
• Syntax :(Inside the class definition)
ret_type fun_name(formal parameters)
{
function body;
}
Defining Member Functions
• Outside the Class Definition
– Member functions that are declared inside a class
have to be defined separately outside the class.
– Their definitions are very much like the normal
functions.
– They should have a function header and a function
body.
– An important difference between a member
function and a normal function is that a member
function incorporates a membership “identity
label” in the header.
…
This label tells the compiler which class
the function belongs to.
Defining Member Functions
• Syntax:(Outside the class definition)
ret_type class_name::fun_name(formal parameters)
{
function body;
}
(scope resolution operator)
Thank youThank you
Ad

More Related Content

What's hot (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
Bhavik Vashi
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
ThamizhselviKrishnam
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
RahulAnanda1
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vishal Patil
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
Bhavik Vashi
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 

Viewers also liked (20)

Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
ForwardBlog Enewzletter
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Encourage the development and diffusion of environmentally friendly technolog...
Encourage the development and diffusion of environmentally friendly technolog...Encourage the development and diffusion of environmentally friendly technolog...
Encourage the development and diffusion of environmentally friendly technolog...
Muhammad Adnan Ejaz
 
Reduced inequalities
Reduced inequalitiesReduced inequalities
Reduced inequalities
Muhammad Adnan Ejaz
 
Sets, functions and groups
Sets, functions and groupsSets, functions and groups
Sets, functions and groups
Muhammad Adnan Ejaz
 
3.b.ed class-scope of ict
3.b.ed class-scope of ict3.b.ed class-scope of ict
3.b.ed class-scope of ict
Santhosh Thomas
 
Neural object classification by pattern recognition of one dimensional data ...
Neural object classification by pattern recognition of one dimensional data...Neural object classification by pattern recognition of one dimensional data...
Neural object classification by pattern recognition of one dimensional data ...
naschibo
 
Software engineering : Layered Architecture
Software engineering : Layered ArchitectureSoftware engineering : Layered Architecture
Software engineering : Layered Architecture
Muhammed Afsal Villan
 
Qualitative research
Qualitative researchQualitative research
Qualitative research
Farhad Mohammad
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Stylistics and it’s relation with linguistics and literature
Stylistics and it’s relation with linguistics and literatureStylistics and it’s relation with linguistics and literature
Stylistics and it’s relation with linguistics and literature
Muhammad Adnan Ejaz
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Array in C
Array in CArray in C
Array in C
Kamal Acharya
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
Kwangshin Oh
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Array within a class
Array within a classArray within a class
Array within a class
AAKASH KUMAR
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Encourage the development and diffusion of environmentally friendly technolog...
Encourage the development and diffusion of environmentally friendly technolog...Encourage the development and diffusion of environmentally friendly technolog...
Encourage the development and diffusion of environmentally friendly technolog...
Muhammad Adnan Ejaz
 
3.b.ed class-scope of ict
3.b.ed class-scope of ict3.b.ed class-scope of ict
3.b.ed class-scope of ict
Santhosh Thomas
 
Neural object classification by pattern recognition of one dimensional data ...
Neural object classification by pattern recognition of one dimensional data...Neural object classification by pattern recognition of one dimensional data...
Neural object classification by pattern recognition of one dimensional data ...
naschibo
 
Software engineering : Layered Architecture
Software engineering : Layered ArchitectureSoftware engineering : Layered Architecture
Software engineering : Layered Architecture
Muhammed Afsal Villan
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Stylistics and it’s relation with linguistics and literature
Stylistics and it’s relation with linguistics and literatureStylistics and it’s relation with linguistics and literature
Stylistics and it’s relation with linguistics and literature
Muhammad Adnan Ejaz
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
Kwangshin Oh
 
Ad

Similar to Data members and member functions (20)

cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.pptcpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
Praveen M Jigajinni
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Lovely Professional University
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
Shweta Shah
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
Rokonuzzaman Rony
 
Class and objects
Class and objectsClass and objects
Class and objects
nafisa rahman
 
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnClass-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
YoussefSameh20
 
Classes
ClassesClasses
Classes
Sheheryar Gull
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Shailendra Veeru
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
Eng Teong Cheah
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
baabtra.com - No. 1 supplier of quality freshers
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
Class
ClassClass
Class
baabtra.com - No. 1 supplier of quality freshers
 
Friend function
Friend functionFriend function
Friend function
Heet Patel
 
Class and object
Class and objectClass and object
Class and object
Prof. Dr. K. Adisesha
 
cpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.pptcpp class unitdfdsfasadfsdASsASass 4.ppt
cpp class unitdfdsfasadfsdASsASass 4.ppt
nandemprasanna
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Anil Kumar
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
manomkpsg
 
static member and static member fumctions.ppt
static member and static member fumctions.pptstatic member and static member fumctions.ppt
static member and static member fumctions.ppt
poojitsaid2021
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
Enam Khan
 
Class objects oopm
Class objects oopmClass objects oopm
Class objects oopm
Shweta Shah
 
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnClass-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
YoussefSameh20
 
[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing[OOP - Lec 09,10,11] Class Members & their Accessing
[OOP - Lec 09,10,11] Class Members & their Accessing
Muhammad Hammad Waseem
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
Eng Teong Cheah
 
classes data type for Btech students.ppt
classes data type for Btech students.pptclasses data type for Btech students.ppt
classes data type for Btech students.ppt
soniasharmafdp
 
Friend function
Friend functionFriend function
Friend function
Heet Patel
 
Ad

Recently uploaded (20)

Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 

Data members and member functions

  • 1. Data Member and Member Function MADE BY: HARSH PATEL :140950107057 DRASHTI PATEL :140950107056 CSE-B
  • 2. Class Specification • Syntax: class class_name { }; Data members Members functions
  • 3. Class Specification • Visibility of Data members & Member functions public - accessed by member functions and all other non-member functions in the program. private - accessed by only member functions of the class. protected - similar to private, but accessed by all the member functions of immediate derived class default - all items defined in the class are private.
  • 4. Data Members • The variables declared inside the class are known as data members. • The private data of a class can be accessed only through the member functions of that class. • Data members Can be of any type, built-in or user-defined
  • 5. Accessing Data Members (inside the class) • Syntax: (single object) data_member; ex: st_id; • Syntax:(array of objects) data_member; ex: st_id;
  • 6. Accessing Data Members (outside the class) • Syntax: (single object) obj_name . datamember; ex: st.st_id; • Syntax:(array of objects) obj_name[i] . datamember; ex: st[i].st_id;
  • 7. Member Function • The functions declared inside the class are known as member functions. • Member functions access the values of the data members and perform operations on the data members . • Their definition can be placed inside the class body, or outside the class body. • Can access both public and private members of the class
  • 8. Defining Member Functions • Member functions can be defined in two places: – Inside the class definition. – Outside the class definition.
  • 9. Defining Member Functions • Inside the Class Definition – Replace the function declaration with the definition of the function inside the class. – When a function is defined inside a class, it is treated as an inline function. – All the restrictions and limitations that apply to an inline function are also applicable to the functions defined inside a class.
  • 10. Defining Member Functions • Syntax :(Inside the class definition) ret_type fun_name(formal parameters) { function body; }
  • 11. Defining Member Functions • Outside the Class Definition – Member functions that are declared inside a class have to be defined separately outside the class. – Their definitions are very much like the normal functions. – They should have a function header and a function body. – An important difference between a member function and a normal function is that a member function incorporates a membership “identity label” in the header. … This label tells the compiler which class the function belongs to.
  • 12. Defining Member Functions • Syntax:(Outside the class definition) ret_type class_name::fun_name(formal parameters) { function body; } (scope resolution operator)