SlideShare a Scribd company logo
3
Most read
5
Most read
7
Most read
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

More Related Content

PPTX
Data members and member functions
PDF
Process fmea
PPTX
IoT Security, Threats and Challenges By V.P.Prabhakaran
PPTX
Type conversion
PPT
PDF
Diagonalization
PPTX
Introduction to trignometry
Data members and member functions
Process fmea
IoT Security, Threats and Challenges By V.P.Prabhakaran
Type conversion
Diagonalization
Introduction to trignometry

What's hot (20)

PPT
Function overloading(c++)
PPTX
[OOP - Lec 07] Access Specifiers
PPTX
Friend function & friend class
PPTX
Java Inheritance - sub class constructors - Method overriding
PPT
Class and object in C++
PDF
Function overloading ppt
PPTX
classes and objects in C++
PDF
PDF
Constructor and Destructor
PDF
Managing I/O in c++
PPTX
07. Virtual Functions
PPTX
class and objects
PPTX
Inheritance in C++
PPTX
OOPS Basics With Example
PPTX
Classes, objects in JAVA
PPTX
Access specifiers(modifiers) in java
PPTX
Type casting
PPTX
Inheritance in c++
PPTX
Inheritance in c++
PPT
Basic concept of OOP's
Function overloading(c++)
[OOP - Lec 07] Access Specifiers
Friend function & friend class
Java Inheritance - sub class constructors - Method overriding
Class and object in C++
Function overloading ppt
classes and objects in C++
Constructor and Destructor
Managing I/O in c++
07. Virtual Functions
class and objects
Inheritance in C++
OOPS Basics With Example
Classes, objects in JAVA
Access specifiers(modifiers) in java
Type casting
Inheritance in c++
Inheritance in c++
Basic concept of OOP's
Ad

Viewers also liked (20)

PPTX
Array within a class
PPTX
[OOP - Lec 19] Static Member Functions
PPTX
Constructors & destructors
PPT
Object Oriented Programming Concepts
PPT
Classes, objects and methods
PPTX
Encourage the development and diffusion of environmentally friendly technolog...
PPTX
Reduced inequalities
PPTX
Sets, functions and groups
PPTX
3.b.ed class-scope of ict
PPT
Neural object classification by pattern recognition of one dimensional data ...
PPTX
Software engineering : Layered Architecture
PPTX
Qualitative research
PPT
Arrays Class presentation
PDF
Lecture17 arrays.ppt
PPTX
Stylistics and it’s relation with linguistics and literature
PDF
C++ ARRAY WITH EXAMPLES
PPT
Array Presentation (EngineerBaBu.com)
PPTX
Arrays In C++
PPTX
Array in C
PPT
Object-Oriented Programming Concepts
Array within a class
[OOP - Lec 19] Static Member Functions
Constructors & destructors
Object Oriented Programming Concepts
Classes, objects and methods
Encourage the development and diffusion of environmentally friendly technolog...
Reduced inequalities
Sets, functions and groups
3.b.ed class-scope of ict
Neural object classification by pattern recognition of one dimensional data ...
Software engineering : Layered Architecture
Qualitative research
Arrays Class presentation
Lecture17 arrays.ppt
Stylistics and it’s relation with linguistics and literature
C++ ARRAY WITH EXAMPLES
Array Presentation (EngineerBaBu.com)
Arrays In C++
Array in C
Object-Oriented Programming Concepts
Ad

Similar to Data members and member functions (20)

PPT
cpp class unitdfdsfasadfsdASsASass 4.ppt
PPTX
object oriented programming-classes and objects.pptx
PPTX
Classes and objects
PPT
4 Classes & Objects
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
PPT
Classes and objects
PPT
static member and static member fumctions.ppt
PPTX
Presentation on class and object in Object Oriented programming.
PPT
Class objects oopm
PPTX
Classes and objects in c++
PPTX
Class and objects
PPTX
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
PPTX
PPTX
Classes and objects
PPTX
[OOP - Lec 09,10,11] Class Members & their Accessing
PDF
Learn C# Programming - Classes & Inheritance
PPT
classes data type for Btech students.ppt
PPTX
Friend function
cpp class unitdfdsfasadfsdASsASass 4.ppt
object oriented programming-classes and objects.pptx
Classes and objects
4 Classes & Objects
classandobjectunit2-150824133722-lva1-app6891.ppt
Classes and objects
static member and static member fumctions.ppt
Presentation on class and object in Object Oriented programming.
Class objects oopm
Classes and objects in c++
Class and objects
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Classes and objects
[OOP - Lec 09,10,11] Class Members & their Accessing
Learn C# Programming - Classes & Inheritance
classes data type for Btech students.ppt
Friend function

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Digital Logic Computer Design lecture notes
PPT
Mechanical Engineering MATERIALS Selection
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
web development for engineering and engineering
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPT
Project quality management in manufacturing
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Welding lecture in detail for understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Well-logging-methods_new................
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Digital Logic Computer Design lecture notes
Mechanical Engineering MATERIALS Selection
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Arduino robotics embedded978-1-4302-3184-4.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
CH1 Production IntroductoryConcepts.pptx
web development for engineering and engineering
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Foundation to blockchain - A guide to Blockchain Tech
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Welding lecture in detail for understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Well-logging-methods_new................
UNIT-1 - COAL BASED THERMAL POWER PLANTS
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT

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)