SlideShare a Scribd company logo
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

PPTX
Functions in c++
PPT
Functions in c++
PPT
16717 functions in C++
 
PPT
Functions in c++
PPT
Functions in C++
PPT
C++ functions
PPTX
Functions in C++ (OOP)
PPT
Functions in C++
Functions in c++
Functions in c++
16717 functions in C++
 
Functions in c++
Functions in C++
C++ functions
Functions in C++ (OOP)
Functions in C++

What's hot (19)

PPTX
Inline Functions and Default arguments
ODP
C++ Function
PPTX
Parameter passing to_functions_in_c
PPT
C++ Function
PPT
C++ Functions
PPT
C++ functions
PPTX
C and C++ functions
PPTX
Functions in C++
PPT
Functions
PPTX
Functions in c++
PPTX
Inline function
PPTX
PARAMETER PASSING MECHANISMS
PPTX
functions of C++
PPTX
Function in c++
PPTX
Function overloading
PDF
Functions in C++
PPT
C++ functions presentation by DHEERAJ KATARIA
PPT
Function overloading(C++)
PPT
Lecture#6 functions in c++
Inline Functions and Default arguments
C++ Function
Parameter passing to_functions_in_c
C++ Function
C++ Functions
C++ functions
C and C++ functions
Functions in C++
Functions
Functions in c++
Inline function
PARAMETER PASSING MECHANISMS
functions of C++
Function in c++
Function overloading
Functions in C++
C++ functions presentation by DHEERAJ KATARIA
Function overloading(C++)
Lecture#6 functions in c++
Ad

Similar to Function class in c++ (20)

PPTX
Object Oriented Programming using C++ Unit 1
PPT
Class objects oopm
PPTX
UNIT3 on object oriented programming.pptx
PPT
static member and static member fumctions.ppt
PPTX
Function in C++, Methods in C++ coding programming
PPTX
OOC MODULE1.pptx
PPTX
Functions1
PPTX
Functions, classes & objects in c++
PPTX
Array within a class
PDF
Classes and objects
PPT
Object and class presentation
PDF
Function overloading ppt
PDF
Computer_Programming_Part_II_Segment_02.pdf
PPTX
Class and object
PPTX
functIONS PROGRAMMING CIII II DJDJKASDJKJASD.pptx
PDF
22 scheme OOPs with C++ BCS306B_module1.pdf
PDF
C++ Object oriented concepts & programming
PPT
APL-2-classes and objects.ppt
PPTX
concepts of object and classes in OOPS.pptx
PPT
Classes in C++ computer language presentation.ppt
Object Oriented Programming using C++ Unit 1
Class objects oopm
UNIT3 on object oriented programming.pptx
static member and static member fumctions.ppt
Function in C++, Methods in C++ coding programming
OOC MODULE1.pptx
Functions1
Functions, classes & objects in c++
Array within a class
Classes and objects
Object and class presentation
Function overloading ppt
Computer_Programming_Part_II_Segment_02.pdf
Class and object
functIONS PROGRAMMING CIII II DJDJKASDJKJASD.pptx
22 scheme OOPs with C++ BCS306B_module1.pdf
C++ Object oriented concepts & programming
APL-2-classes and objects.ppt
concepts of object and classes in OOPS.pptx
Classes in C++ computer language presentation.ppt
Ad

More from Kumar (20)

PPT
Graphics devices
PPT
Fill area algorithms
PDF
region-filling
PDF
Bresenham derivation
PPT
Bresenham circles and polygons derication
PPTX
Introductionto xslt
PPTX
Extracting data from xml
PPTX
Xml basics
PPTX
XML Schema
PPTX
Publishing xml
PPTX
DTD
PPTX
Applying xml
PPTX
Introduction to XML
PDF
How to deploy a j2ee application
PDF
JNDI, JMS, JPA, XML
PDF
EJB Fundmentals
PDF
JSP and struts programming
PDF
java servlet and servlet programming
PDF
Introduction to JDBC and JDBC Drivers
PDF
Introduction to J2EE
Graphics devices
Fill area algorithms
region-filling
Bresenham derivation
Bresenham circles and polygons derication
Introductionto xslt
Extracting data from xml
Xml basics
XML Schema
Publishing xml
DTD
Applying xml
Introduction to XML
How to deploy a j2ee application
JNDI, JMS, JPA, XML
EJB Fundmentals
JSP and struts programming
java servlet and servlet programming
Introduction to JDBC and JDBC Drivers
Introduction to J2EE

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
Cell Types and Its function , kingdom of life
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Institutional Correction lecture only . . .
PDF
Business Ethics Teaching Materials for college
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Pre independence Education in Inndia.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Basic Mud Logging Guide for educational purpose
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Cell Structure & Organelles in detailed.
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
master seminar digital applications in india
Cell Types and Its function , kingdom of life
102 student loan defaulters named and shamed – Is someone you know on the list?
Institutional Correction lecture only . . .
Business Ethics Teaching Materials for college
Renaissance Architecture: A Journey from Faith to Humanism
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Pre independence Education in Inndia.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Supply Chain Operations Speaking Notes -ICLT Program
Basic Mud Logging Guide for educational purpose
2.FourierTransform-ShortQuestionswithAnswers.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Cell Structure & Organelles in detailed.
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf

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 }