SlideShare a Scribd company logo
1 of 13
Inheritance and type casting
Inheritance
• It is a mechanism of creating a new class
from an already defined class
• The new class contains all attributes of the
old class in addition to some of its own
attributes.
• (REFER Ist UNIT PPT FOR
INHERITANCE AND POLYMORPHISM
CONCEPTS)
Virtual Functions
 C++ matches a function call with the correct
function definition at compile time
 known as static binding
 the compiler can match a function call with the
correct function definition at run time
 known as dynamic binding.
 declare a function with the keyword virtual if you
want the compiler to use dynamic binding for that
specific function.
Example
• class A {
public:
virtual void f() { cout << "Class A" << endl; }
};
• class B: public A {
• public:
void f(int) { cout << "Class B" << endl; }
};
• class C: public B {
• public:
void f() { cout << "Class C" << endl; }
};
“Pure”ly Virtual
 a virtual function declared with no definition
 base class contains no implementation at all
 class containing a pure virtual function is an
abstract class
 similar to Java interfaces
 cannot instantiate from abstract classes
 enforces a design through inheritance hierarchy
 inherited classes must define implementation
Example
• class A {
public:
virtual void f() = 0; // pure virtual
};
• class B: public A {
• public:
void f() { cout << "Class B" << endl; }
};
• class C: public B {
• public:
void f() { cout << "Class C" << endl; }
};
Run Time Type Information (RTTI)
• Always exists in OOP: a prerequisite for
dynamic binding
• Accessible to programmer?
– Not necessarily in statically typed languages
• Many things can be done without it!
– Almost always in dynamically typed
languages
• Without it, it is impossible to be sure that an
object will recognize a message!
• In LST, RTTI is the information accessible from
the instance_of pointer
RTTI in C++
class typeinfo {
public:
virtual ~typeinfo(void);
bool operator==(const typeinfo&) const;
bool operator!=(const typeinfo&) const;
bool before(const typeinfo&) const;
const char *name(void) const;
private:
typeinfo(const typeinfo&);
typeinfo& operator= (const typeinfo&);
//.. Implementation dependent fields
};
class Base {
...
};
void f(Base *p)
{
const typeinfo& a = typeid(p);
// Type information for Base *
const typeinfo& a = typeid(*p);
// Actual run time type of *p
}
No RTTI in early
versions of the
language.
No feature should
incur a cost if not
• Dynamic Typing: no constraints on the
values
• stored in a variable.
• – Usually implies reference semantics
• • Run‐time type information: dynamic type
is
• associated with the value.
– –
};
Dynamic binding and casting
Dynamic casting
• Casting operator is for polymorphic object casting ,so that
it can cast from one object to another object.
• Dynamic cast is also called as safe cast.it succeeds only
when the pointer or reference being cast is an object of the
target type or derived type from it.
• The syntax is written as dynamic cast<ToobjectptrOr
ref>(FromobjectPtrOrRef)
• If we have a base class and a derived class,casting from
derived pointer to base pointer always succeeds.The
casting from base pointer to derived can be succeed only if
base is actually pointing to an object of derived one.
Rtti and templates
• If we want to test the type of the actual
variable and try to provide validations
according to the type we can use RTTI
for that.
Cross casting
• It refers to casting from derived to proper base class when there are multiple base classes in case of multiple inheritance.
• The
• dynamic_cast
• feature of C++ affords another kind of solution -- cross casting.
• Consider the following code.
• class A {public: virtual ~A();};
• class B {public: virtual ~B();};
• class C : public A, public B {};
• A* ap = new C;
• B* bp = dynamic_cast<B*>(ap);
• Notice that classes
• A
• and
• B
• are completely unrelated. Now when we create an
• instance of
• C
• we can safely upcast it to an
• A*
• . However, we can now take that pointer to
• A
• and
• cross cast
• it to a pointer to a B. This works because the
• A
• pointer ‘
• ap
• ’ really points at
• a
• C
• object; and
• C
• derives from
• B
• .
• Thus, we have cast
• accross
• the inheritance hierarchy between completely unrelated
• classes. It should be noted that this will
• not
Down casting
rectangle::rectangle(float h, float w, int c, int l):pr(c, l)
{
height = h;
width = w;
xpos = 0;
ypos = 0;
};
void main()
{
rectangle rc(3.0, 2.0, 1, 3);
C++ statements;
}

More Related Content

Similar to UNIT IV (1).ppt

New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)rashmita_mishra
 
C questions
C questionsC questions
C questionsparm112
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#Sagar Pednekar
 
Presentation on Polymorphism (SDS).ppt
Presentation on Polymorphism (SDS).pptPresentation on Polymorphism (SDS).ppt
Presentation on Polymorphism (SDS).pptHarpreetKaur1382
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++Mohammad Shaker
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfnisarmca
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptxAtharvPotdar2
 
Louis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLouis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLou Loizides
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming IntroLou Loizides
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginnersophoeutsen2
 

Similar to UNIT IV (1).ppt (20)

New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
C questions
C questionsC questions
C questions
 
java vs C#
java vs C#java vs C#
java vs C#
 
Constructor
ConstructorConstructor
Constructor
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Presentation on Polymorphism (SDS).ppt
Presentation on Polymorphism (SDS).pptPresentation on Polymorphism (SDS).ppt
Presentation on Polymorphism (SDS).ppt
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
C#2
C#2C#2
C#2
 
c++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdfc++-language-1208539706757125-9.pdf
c++-language-1208539706757125-9.pdf
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx11.C++Polymorphism [Autosaved].pptx
11.C++Polymorphism [Autosaved].pptx
 
Louis Loizides iOS Programming Introduction
Louis Loizides iOS Programming IntroductionLouis Loizides iOS Programming Introduction
Louis Loizides iOS Programming Introduction
 
iOS Programming Intro
iOS Programming IntroiOS Programming Intro
iOS Programming Intro
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 

More from VGaneshKarthikeyan

Unit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxUnit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxVGaneshKarthikeyan
 
Linear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxLinear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxVGaneshKarthikeyan
 
K-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxK-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxVGaneshKarthikeyan
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxVGaneshKarthikeyan
 
Refined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptRefined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptVGaneshKarthikeyan
 
randomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptrandomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptVGaneshKarthikeyan
 
stochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptstochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptVGaneshKarthikeyan
 
1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptxVGaneshKarthikeyan
 
Neural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.pptNeural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.pptVGaneshKarthikeyan
 
Lecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.pptLecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.pptVGaneshKarthikeyan
 
1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.pptVGaneshKarthikeyan
 
Python_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.pptPython_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.pptVGaneshKarthikeyan
 
1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptx1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptxVGaneshKarthikeyan
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridVGaneshKarthikeyan
 
Refined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.pptRefined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.pptVGaneshKarthikeyan
 
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.pptRefined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.pptVGaneshKarthikeyan
 
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.pptRefined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.pptVGaneshKarthikeyan
 
Bias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdfBias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdfVGaneshKarthikeyan
 
Refined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.pptRefined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.pptVGaneshKarthikeyan
 
Lecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTXLecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTXVGaneshKarthikeyan
 

More from VGaneshKarthikeyan (20)

Unit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxUnit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptx
 
Linear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxLinear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptx
 
K-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxK-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptx
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
 
Refined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptRefined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.ppt
 
randomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptrandomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.ppt
 
stochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptstochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.ppt
 
1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx1.10 Tuples_sets_usage_applications_advantages.pptx
1.10 Tuples_sets_usage_applications_advantages.pptx
 
Neural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.pptNeural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.ppt
 
Lecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.pptLecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.ppt
 
1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt
 
Python_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.pptPython_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.ppt
 
1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptx1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptx
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybrid
 
Refined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.pptRefined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.ppt
 
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.pptRefined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
 
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.pptRefined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
 
Bias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdfBias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdf
 
Refined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.pptRefined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.ppt
 
Lecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTXLecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTX
 

Recently uploaded

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 

Recently uploaded (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 

UNIT IV (1).ppt

  • 2. Inheritance • It is a mechanism of creating a new class from an already defined class • The new class contains all attributes of the old class in addition to some of its own attributes. • (REFER Ist UNIT PPT FOR INHERITANCE AND POLYMORPHISM CONCEPTS)
  • 3. Virtual Functions  C++ matches a function call with the correct function definition at compile time  known as static binding  the compiler can match a function call with the correct function definition at run time  known as dynamic binding.  declare a function with the keyword virtual if you want the compiler to use dynamic binding for that specific function.
  • 4. Example • class A { public: virtual void f() { cout << "Class A" << endl; } }; • class B: public A { • public: void f(int) { cout << "Class B" << endl; } }; • class C: public B { • public: void f() { cout << "Class C" << endl; } };
  • 5. “Pure”ly Virtual  a virtual function declared with no definition  base class contains no implementation at all  class containing a pure virtual function is an abstract class  similar to Java interfaces  cannot instantiate from abstract classes  enforces a design through inheritance hierarchy  inherited classes must define implementation
  • 6. Example • class A { public: virtual void f() = 0; // pure virtual }; • class B: public A { • public: void f() { cout << "Class B" << endl; } }; • class C: public B { • public: void f() { cout << "Class C" << endl; } };
  • 7. Run Time Type Information (RTTI) • Always exists in OOP: a prerequisite for dynamic binding • Accessible to programmer? – Not necessarily in statically typed languages • Many things can be done without it! – Almost always in dynamically typed languages • Without it, it is impossible to be sure that an object will recognize a message! • In LST, RTTI is the information accessible from the instance_of pointer
  • 8. RTTI in C++ class typeinfo { public: virtual ~typeinfo(void); bool operator==(const typeinfo&) const; bool operator!=(const typeinfo&) const; bool before(const typeinfo&) const; const char *name(void) const; private: typeinfo(const typeinfo&); typeinfo& operator= (const typeinfo&); //.. Implementation dependent fields }; class Base { ... }; void f(Base *p) { const typeinfo& a = typeid(p); // Type information for Base * const typeinfo& a = typeid(*p); // Actual run time type of *p } No RTTI in early versions of the language. No feature should incur a cost if not
  • 9. • Dynamic Typing: no constraints on the values • stored in a variable. • – Usually implies reference semantics • • Run‐time type information: dynamic type is • associated with the value. – – }; Dynamic binding and casting
  • 10. Dynamic casting • Casting operator is for polymorphic object casting ,so that it can cast from one object to another object. • Dynamic cast is also called as safe cast.it succeeds only when the pointer or reference being cast is an object of the target type or derived type from it. • The syntax is written as dynamic cast<ToobjectptrOr ref>(FromobjectPtrOrRef) • If we have a base class and a derived class,casting from derived pointer to base pointer always succeeds.The casting from base pointer to derived can be succeed only if base is actually pointing to an object of derived one.
  • 11. Rtti and templates • If we want to test the type of the actual variable and try to provide validations according to the type we can use RTTI for that.
  • 12. Cross casting • It refers to casting from derived to proper base class when there are multiple base classes in case of multiple inheritance. • The • dynamic_cast • feature of C++ affords another kind of solution -- cross casting. • Consider the following code. • class A {public: virtual ~A();}; • class B {public: virtual ~B();}; • class C : public A, public B {}; • A* ap = new C; • B* bp = dynamic_cast<B*>(ap); • Notice that classes • A • and • B • are completely unrelated. Now when we create an • instance of • C • we can safely upcast it to an • A* • . However, we can now take that pointer to • A • and • cross cast • it to a pointer to a B. This works because the • A • pointer ‘ • ap • ’ really points at • a • C • object; and • C • derives from • B • . • Thus, we have cast • accross • the inheritance hierarchy between completely unrelated • classes. It should be noted that this will • not
  • 13. Down casting rectangle::rectangle(float h, float w, int c, int l):pr(c, l) { height = h; width = w; xpos = 0; ypos = 0; }; void main() { rectangle rc(3.0, 2.0, 1, 3); C++ statements; }

Editor's Notes

  1. 7
  2. 8