SlideShare a Scribd company logo
1 of 15
Function Overloading
and Overriding
Overloading Introduction
One of the more powerful features for code readability and
usability is that of overloading.
Like most things, it can be used for both good andevil.
Function overloading is the availability of various functions within
a class that differ from each other in function signature i.e.
various functions share same name with different parameter
types or number of parameters.
Functions in C++
A function in C++ is not uniquely identified by its name
alone.
Each function has a function signature, consisting of two
elements.
The name of the method
The order and type of its parameters.
Together, these act as the unique identifier for a C++
method.
The following thus are two different functions:
addTwo (int x, int y);
addTwo (float x, float y);
Function Overloading
The process of providing more than one functions with
the same name is called method overloading.
We say that these functions have been overloaded.
Overloading makes sure that we can provide a consistent
and clear interface to our methods regardless of the
parameters type.
We don’t need addTwoInts and addTwoFloats, for example.
Function Overloading
The compiler works out which of the methods to call
based on the parameters it is passed.
It will check for the method that has a matching signature.
It will execute that method only.
If no matching signatures are found, a compile-time error
will be displayed.
Function Overloading
int add_nums (int one, int two) {
return one + two;
}
int add_nums (float one, float two) {
return (ceil (one + two));
}
int main() {
int answer_one, answer_two, answer_three;
answer_one = add_nums (1, 2); // Fine
answer_two = add_nums (1.0f, 2.0f); // Fine
answer_three = add_nums (1.0f, 2) // Error
}
Function Overriding
A function in child class overrides a function in parent
class if they have the same name and type signature.
Classes in which functions are defined must be in a
parent-child relationship.
Overloading deals with multiple functions in the same
class with the same name but different signatures
Overriding deals with two functions, one in a parent class
and one in a child class, that have the same signature
Function Overriding
class Base
{
protected:
void myFunc() { cout<<"Base Class’ Function"; }
};
class Derived: public Base {
public:
void myFunc() { cout<<"Derived Class’ Function"; }
void myFunc(int a)
{
cout<<"Derived Class’ Function with Parameter
Value“<<a;
}
};
Function Overriding
Function Overriding
To access the overridden function of base class from
derived class, scope resolution operator ::.
Following statement is used in derived class to access
the base class get_data() function:
A::get_data; // Calling get_data() of class A.
Code
classA
{
public:
void fun()
cout << "n-> BASE <-n"; }{
};
class B:publicA {
public:
void fun()
{
A::fun();
cout << "-> DERIVED <-nn";
}
};
void main()
{
B b1;
b1.fun();
}
Output
Code
classA
{
public:
void fun()
cout << "n-> BASE <-n"; }{
};
class B:publicA {
public:
void fun()
{
cout << "-> DERIVED <-nn";
}
};
void main()
{
A *a1;
B b1;
a1=&b1;
a1->fun();
}
Virtual function
classA
{
public:
virtual void fun()
cout << "n-> BASE <-n"; }{
};
class B:publicA {
public:
void fun()
{
cout << "-> DERIVED <-nn";
}
};
void main()
{
A *a1;
B b1;
a1=&b1;
a1->fun();
}
Output

More Related Content

What's hot

What's hot (18)

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Declaration merging | Typescript
Declaration merging | TypescriptDeclaration merging | Typescript
Declaration merging | Typescript
 
ccc
cccccc
ccc
 
C++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismC++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphism
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-22. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
2. 엔티티 매핑(entity mapping) 2 3 롬복(lombok)소개-2
 
Pointers
PointersPointers
Pointers
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
All experiment of java
All experiment of javaAll experiment of java
All experiment of java
 
Object Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. PolymorphismObject Oriented Programming - 7.2. Polymorphism
Object Oriented Programming - 7.2. Polymorphism
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
Some basic FP concepts
Some basic FP conceptsSome basic FP concepts
Some basic FP concepts
 

Similar to Function overloading

function overloading
function overloadingfunction overloading
function overloadingAvaniNakum
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6patcha535
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxMalligaarjunanN
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshowilias ahmed
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & TemplatesMeghaj Mallick
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java Janu Jahnavi
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloadingPrincess Sam
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloadingPrincess Sam
 
Function & procedure
Function & procedureFunction & procedure
Function & procedureatishupadhyay
 
Inheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxInheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxABHINAVARYANCSEA301
 

Similar to Function overloading (20)

function overloading
function overloadingfunction overloading
function overloading
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & Templates
 
Functions1
Functions1Functions1
Functions1
 
Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Functions
FunctionsFunctions
Functions
 
Bc0037
Bc0037Bc0037
Bc0037
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
4. function
4. function4. function
4. function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C plusplus
C plusplusC plusplus
C plusplus
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
Notes on c++
Notes on c++Notes on c++
Notes on c++
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
My c++
My c++My c++
My c++
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
Inheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxInheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptx
 

More from zindadili

Exception handling
Exception handlingException handling
Exception handlingzindadili
 
Exception handling
Exception handlingException handling
Exception handlingzindadili
 
Virtual function
Virtual functionVirtual function
Virtual functionzindadili
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaingzindadili
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2zindadili
 
Polymorphism
PolymorphismPolymorphism
Polymorphismzindadili
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritancezindadili
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritancezindadili
 
Multiple inheritance
Multiple inheritanceMultiple inheritance
Multiple inheritancezindadili
 
Abstraction1
Abstraction1Abstraction1
Abstraction1zindadili
 
Access specifier
Access specifierAccess specifier
Access specifierzindadili
 
Friend function
Friend functionFriend function
Friend functionzindadili
 

More from zindadili (20)

Namespaces
NamespacesNamespaces
Namespaces
 
Namespace1
Namespace1Namespace1
Namespace1
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Templates2
Templates2Templates2
Templates2
 
Templates1
Templates1Templates1
Templates1
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Aggregation
AggregationAggregation
Aggregation
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Hybrid inheritance
Hybrid inheritanceHybrid inheritance
Hybrid inheritance
 
Multiple inheritance
Multiple inheritanceMultiple inheritance
Multiple inheritance
 
Abstraction1
Abstraction1Abstraction1
Abstraction1
 
Abstraction
AbstractionAbstraction
Abstraction
 
Access specifier
Access specifierAccess specifier
Access specifier
 
Inheritance
InheritanceInheritance
Inheritance
 
Friend function
Friend functionFriend function
Friend function
 
Enum
EnumEnum
Enum
 

Recently uploaded

ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 

Recently uploaded (20)

ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 

Function overloading

  • 2. Overloading Introduction One of the more powerful features for code readability and usability is that of overloading. Like most things, it can be used for both good andevil. Function overloading is the availability of various functions within a class that differ from each other in function signature i.e. various functions share same name with different parameter types or number of parameters.
  • 3. Functions in C++ A function in C++ is not uniquely identified by its name alone. Each function has a function signature, consisting of two elements. The name of the method The order and type of its parameters. Together, these act as the unique identifier for a C++ method. The following thus are two different functions: addTwo (int x, int y); addTwo (float x, float y);
  • 4. Function Overloading The process of providing more than one functions with the same name is called method overloading. We say that these functions have been overloaded. Overloading makes sure that we can provide a consistent and clear interface to our methods regardless of the parameters type. We don’t need addTwoInts and addTwoFloats, for example.
  • 5. Function Overloading The compiler works out which of the methods to call based on the parameters it is passed. It will check for the method that has a matching signature. It will execute that method only. If no matching signatures are found, a compile-time error will be displayed.
  • 6. Function Overloading int add_nums (int one, int two) { return one + two; } int add_nums (float one, float two) { return (ceil (one + two)); } int main() { int answer_one, answer_two, answer_three; answer_one = add_nums (1, 2); // Fine answer_two = add_nums (1.0f, 2.0f); // Fine answer_three = add_nums (1.0f, 2) // Error }
  • 7. Function Overriding A function in child class overrides a function in parent class if they have the same name and type signature. Classes in which functions are defined must be in a parent-child relationship. Overloading deals with multiple functions in the same class with the same name but different signatures Overriding deals with two functions, one in a parent class and one in a child class, that have the same signature
  • 8. Function Overriding class Base { protected: void myFunc() { cout<<"Base Class’ Function"; } }; class Derived: public Base { public: void myFunc() { cout<<"Derived Class’ Function"; } void myFunc(int a) { cout<<"Derived Class’ Function with Parameter Value“<<a; } };
  • 10. Function Overriding To access the overridden function of base class from derived class, scope resolution operator ::. Following statement is used in derived class to access the base class get_data() function: A::get_data; // Calling get_data() of class A.
  • 11. Code classA { public: void fun() cout << "n-> BASE <-n"; }{ }; class B:publicA { public: void fun() { A::fun(); cout << "-> DERIVED <-nn"; } }; void main() { B b1; b1.fun(); }
  • 13. Code classA { public: void fun() cout << "n-> BASE <-n"; }{ }; class B:publicA { public: void fun() { cout << "-> DERIVED <-nn"; } }; void main() { A *a1; B b1; a1=&b1; a1->fun(); }
  • 14. Virtual function classA { public: virtual void fun() cout << "n-> BASE <-n"; }{ }; class B:publicA { public: void fun() { cout << "-> DERIVED <-nn"; } }; void main() { A *a1; B b1; a1=&b1; a1->fun(); }