CO2402 Advanced Programming with C++ Lecture 9 Notes
7 views 0 purchase
Course
Advanced Programming with C++ (CO2402)
Institution
University Of Central Lancashire Preston (UClan)
This document contains the comprehensive notes from Lecture 9 of the CO2402 course on Advanced Programming with C++. The lecture focuses on advanced concepts of inheritance and function overriding, crucial elements in object-oriented programming. Key topics covered include polymorphism, virtual fun...
University of Central Lancashire Preston (UClan)
Unknown
Advanced Programming with C++ (CO2402)
All documents for this subject (19)
Seller
Follow
BpoBpo
Reviews received
Content preview
CO2402: Advanced Programming
with C++ Lecture 9
Introduction to Inheritance and Function Overriding
1. Review of Inheritance
o Base Class: The original class from which others inherit.
o Derived Class: The class that inherits from the base class.
o Public inheritance allows the derived class to access public
and protected members of the base class.
2. Function Overriding
o Occurs when a derived class defines a function with the same
name and parameters as a function in its base class. This
allows the derived class to provide a specific implementation.
Example:
3. Calling Overridden Functions
, o The version of the function called depends on the type of
the object or pointer. For objects, the derived class's
version is called if the object is of the derived type.
Example:
The base class function can still be called using the scope
resolution operator.
Polymorphism
1. Concept and Importance
o Polymorphism allows objects of different classes to be treated
as objects of a common base class. It enables the invocation
of derived class methods through base class pointers or
references.
Example:
The output is "Message from base class" because the function
is bound at compile time based on the pointer type (CBase*).
2. Virtual Functions
o Virtual functions enable polymorphism by allowing derived
classes to override base class methods. The virtual keyword in
the base class function declaration signals the compiler to use
dynamic binding.
Example:
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller BpoBpo. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $3.86. You're not tied to anything after your purchase.