SlideShare uma empresa Scribd logo
1 de 13
Classes in C++
Presented by: Sheheryar Gull
Reg # 130101071
Classes are user-defined (programmer-
defined) types.
Data (data members)
Functions (member functions or methods)
In other words, they are structures +
functions
Classes in C++
Classes in C++
 A class definition begins with the keyword
class.
 The body of the class is contained within a set
of braces, { } ; (notice the semi-colon).
class class_name
{
….
….
….
};
Class body (data member +
methods)
Any valid identifier
Classes in C++
 Within the body, the keywords private: and
public: specify the access level of the
members of the class.
 the default is private.
 Usually, the data members of a class are
declared in the private: section of the class
and the member functions are in public:
section.
Classes in C++

class class_name
{
private:
…
…
…
public:
…
…
…
};
Public members or
methods
private members or
methods
Classes in C++
 Member access specifiers
 public:
 can be accessed outside the class directly.
 The public stuff is the interface.
 private:
 Accessible only to member functions of
class
 Private members and methods are for
internal use only.
Creating an object of a
Class
 Declaring a variable of a class type creates an
object.You can have many variables of the same
type (class).
 Instantiation
 Once an object of a certain class is instantiated, a
new memory location is created for it to store its
data members and code
 You can instantiate many objects from a class
type.
Special Member Functions
 Constructor:
 Public function member
 called when a new object is created (instantiated).
 Initialize data members.
 Same name as class
 No return type
 Several constructors
 Function overloading
Implementing class methods
 Class implementation: writing the code of class
methods.
 There are two ways:
1. Member functions defined outside class
 Using Binary scope resolution operator (::)
 “Ties” member name to class name
 Uniquely identify functions of particular class
 Different classes can have member functions
with same name
 Format for defining member functions
Return Type Class Name::
Member Function Name( ){
…
}
Destructors
 Destructors
 Special member function
 Same name as class
 Preceded with tilde (~)
 No arguments
 No return value
 Cannot be overloaded
 Before system reclaims object’s memory
 Reuse memory for new objects
 Mainly used to de-allocate dynamic memory locations
Classes
Classes
Classes

Mais conteúdo relacionado

Mais procurados

Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
Tech_MX
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objects
Deepak Singh
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
Ravi_Kant_Sahu
 

Mais procurados (20)

Nested class in java
Nested class in javaNested class in java
Nested class in java
 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in java
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Class properties
Class propertiesClass properties
Class properties
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
C++ constructors
C++ constructorsC++ constructors
C++ constructors
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
creating objects and Class methods
creating objects and Class methodscreating objects and Class methods
creating objects and Class methods
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
 
Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objects
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 

Semelhante a Classes

Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 

Semelhante a Classes (20)

Class and object
Class and objectClass and object
Class and object
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Class and object
Class and objectClass and object
Class and object
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
[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
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
C++ classes
C++ classesC++ classes
C++ classes
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1
 
c++ introduction
c++ introductionc++ introduction
c++ introduction
 
c++ lecture 1
c++ lecture 1c++ lecture 1
c++ lecture 1
 
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
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
C++ classes
C++ classesC++ classes
C++ classes
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 

Classes

  • 1. Classes in C++ Presented by: Sheheryar Gull Reg # 130101071
  • 2. Classes are user-defined (programmer- defined) types. Data (data members) Functions (member functions or methods) In other words, they are structures + functions Classes in C++
  • 3. Classes in C++  A class definition begins with the keyword class.  The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name { …. …. …. }; Class body (data member + methods) Any valid identifier
  • 4. Classes in C++  Within the body, the keywords private: and public: specify the access level of the members of the class.  the default is private.  Usually, the data members of a class are declared in the private: section of the class and the member functions are in public: section.
  • 5. Classes in C++  class class_name { private: … … … public: … … … }; Public members or methods private members or methods
  • 6. Classes in C++  Member access specifiers  public:  can be accessed outside the class directly.  The public stuff is the interface.  private:  Accessible only to member functions of class  Private members and methods are for internal use only.
  • 7. Creating an object of a Class  Declaring a variable of a class type creates an object.You can have many variables of the same type (class).  Instantiation  Once an object of a certain class is instantiated, a new memory location is created for it to store its data members and code  You can instantiate many objects from a class type.
  • 8. Special Member Functions  Constructor:  Public function member  called when a new object is created (instantiated).  Initialize data members.  Same name as class  No return type  Several constructors  Function overloading
  • 9. Implementing class methods  Class implementation: writing the code of class methods.  There are two ways: 1. Member functions defined outside class  Using Binary scope resolution operator (::)  “Ties” member name to class name  Uniquely identify functions of particular class  Different classes can have member functions with same name  Format for defining member functions Return Type Class Name:: Member Function Name( ){ … }
  • 10. Destructors  Destructors  Special member function  Same name as class  Preceded with tilde (~)  No arguments  No return value  Cannot be overloaded  Before system reclaims object’s memory  Reuse memory for new objects  Mainly used to de-allocate dynamic memory locations