SlideShare a Scribd company logo
1 of 15
Lec-07
Function,Class
Inline Function
Inline functions are functions where the call is made to
inline functions. The actual code then gets placed in the
calling program.
Once you define an inline function, using the 'inline'
keyword, whenever you call that function the compiler
will replace the function call with the actual code from
the function.
General form
inline datatype function_name(arguments)
Inline Function
#include <iostream>
using namespace std;
int func(int);
void main( )
{
int x;
cout << "n Enter the Input Value: ";
cin>>x;
cout << "n The Output is: " << func(x);
}
inline int func(int x1)
{
return 5*x1;
}
Note:-Inline functions will save time and are useful if the function is
very small. If the function is large, use of inline functions must be
avoided.
Function Overloading
• Using same function name for different purposes is
called function overloading.
• Function will perform different operations depending
on the argument list in the function call
Ex. int add(int ,int)
int add(int , float)
int add(float ,int)
int add(int ,int,int)

• A function is executed when the function call matches
the prototype with same number and type of
argument.
Function Overloading
• Function selection involves the following steps..
1. Tries to finds the exact match in which types of actual
argument are same.
2. If actual match is not found then compiler uses the
type coercion :promotion to find the match.
3. if conversion is possible to have multiple matches
then compiler will generate the error.
Ex . long sqr(long n)
double sqr(double n)
Function call
sqr(10) cause the error.
C structure revisited
• Provides a method to packing together data of
different type.
Ex struct complex
{
int real;
int img;
};
struct complex c1,c2;
Limitation of c structure:
1. c3=c1+c2 //illegal
2. Data hiding
C++ structure
• C++ supports all the features of the structures as
defined in c.
• C++ structure can have both function and data.
• Support data hiding(by defining members as private).
• Default members are public .
Class
• A class is a user defined data type
• General form of class declaration
class class_name {
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;

};
Class
• function and variable collectively called class
members.
• Variables declared inside the class is known as data
member and function declared inside the class is
known as member function.
• Only the member function can have access to the
private data member and private member function.
• Default members are private.
Class declaration
• Class declaration:class item{
int number; //variable declaration
float price;
public:
void getdata(int ,float); //function declaration
void putdata(void);
};
Defining member function
• Member function can be defined in two places
1. Outside the class definition.
2. Inside the class definition
Outside the class definition
• Genral form :Return_type class_name::function_name(parameter list)
{
function body;
}
Ex . void item :: getdata(int x,float y)
{
number=x;
price=y;
}
Inside the class definition
• Genral form :Return_type function_name(parameter list)
{
function body;
}
Ex . void getdata(int x,float y)
{
number=x;
price=y;
}
Accessing members of a class
• Accessing data members
object_name.datamember;
• Accessing member function
object_name.function(actual parameters);
item m;
m.getdata(5,6.5)
Note : Members are called by using their name only
inside the member function.
Private Member Function
• A private member function can only be called by another
function that is member of its class even an object can not
invoke the private function of a class using the dot operator.
Class sample {
int main()
int m;
{
void read(void)
sample s1;
public:
s1.read(); //error
void update(void);
s1.update();
};
}
void sample :: update(void)
{
read(); //simple call no object is used
}

More Related Content

What's hot

C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 

What's hot (19)

Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions
FunctionsFunctions
Functions
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Inline function
Inline functionInline function
Inline function
 
PARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMSPARAMETER PASSING MECHANISMS
PARAMETER PASSING MECHANISMS
 
functions of C++
functions of C++functions of C++
functions of C++
 
Function in c++
Function in c++Function in c++
Function in c++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 

Similar to Function class in c++

Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
Alisha Korpal
 

Similar to Function class in c++ (20)

Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Functions
FunctionsFunctions
Functions
 
Functions
FunctionsFunctions
Functions
 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
 
Function different types of funtion
Function different types of funtionFunction different types of funtion
Function different types of funtion
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptxconcepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptx
 

More from Kumar

More from Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 

Function class in c++

  • 2. Inline Function Inline functions are functions where the call is made to inline functions. The actual code then gets placed in the calling program. Once you define an inline function, using the 'inline' keyword, whenever you call that function the compiler will replace the function call with the actual code from the function. General form inline datatype function_name(arguments)
  • 3. Inline Function #include <iostream> using namespace std; int func(int); void main( ) { int x; cout << "n Enter the Input Value: "; cin>>x; cout << "n The Output is: " << func(x); } inline int func(int x1) { return 5*x1; } Note:-Inline functions will save time and are useful if the function is very small. If the function is large, use of inline functions must be avoided.
  • 4. Function Overloading • Using same function name for different purposes is called function overloading. • Function will perform different operations depending on the argument list in the function call Ex. int add(int ,int) int add(int , float) int add(float ,int) int add(int ,int,int) • A function is executed when the function call matches the prototype with same number and type of argument.
  • 5. Function Overloading • Function selection involves the following steps.. 1. Tries to finds the exact match in which types of actual argument are same. 2. If actual match is not found then compiler uses the type coercion :promotion to find the match. 3. if conversion is possible to have multiple matches then compiler will generate the error. Ex . long sqr(long n) double sqr(double n) Function call sqr(10) cause the error.
  • 6. C structure revisited • Provides a method to packing together data of different type. Ex struct complex { int real; int img; }; struct complex c1,c2; Limitation of c structure: 1. c3=c1+c2 //illegal 2. Data hiding
  • 7. C++ structure • C++ supports all the features of the structures as defined in c. • C++ structure can have both function and data. • Support data hiding(by defining members as private). • Default members are public .
  • 8. Class • A class is a user defined data type • General form of class declaration class class_name { private: variable declaration; function declaration; public: variable declaration; function declaration; };
  • 9. Class • function and variable collectively called class members. • Variables declared inside the class is known as data member and function declared inside the class is known as member function. • Only the member function can have access to the private data member and private member function. • Default members are private.
  • 10. Class declaration • Class declaration:class item{ int number; //variable declaration float price; public: void getdata(int ,float); //function declaration void putdata(void); };
  • 11. Defining member function • Member function can be defined in two places 1. Outside the class definition. 2. Inside the class definition
  • 12. Outside the class definition • Genral form :Return_type class_name::function_name(parameter list) { function body; } Ex . void item :: getdata(int x,float y) { number=x; price=y; }
  • 13. Inside the class definition • Genral form :Return_type function_name(parameter list) { function body; } Ex . void getdata(int x,float y) { number=x; price=y; }
  • 14. Accessing members of a class • Accessing data members object_name.datamember; • Accessing member function object_name.function(actual parameters); item m; m.getdata(5,6.5) Note : Members are called by using their name only inside the member function.
  • 15. Private Member Function • A private member function can only be called by another function that is member of its class even an object can not invoke the private function of a class using the dot operator. Class sample { int main() int m; { void read(void) sample s1; public: s1.read(); //error void update(void); s1.update(); }; } void sample :: update(void) { read(); //simple call no object is used }