Advanced Inheritance & Polymorphism - example with Array of Objects (in-depth Data Structures & OOP)
HTML-код
- Опубликовано: 25 июн 2024
- This video provides an in-depth explanation of the relationship between Arrays of objects and OOP concepts such as Inheritance and Polymorphism. It is a programming tutorial designed to teach you about data structures, object-oriented programming, and best practices for writing code. Through a practical example, you will learn how to create arrays that hold a collection of different objects. By the end of this coding exercise, you will have a solid understanding of how to implement parent-child relationships between classes and write reusable code. Additionally, you will learn how to implement polymorphic behavior and write efficient code.
To put your knowledge into practice, I have also prepared a practical task for you. This hands-on challenge will ensure that you understand these concepts and are able to use them in your own programming projects.
📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.
☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. Use the link to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
Related videos:
Array Data Structure (for absolute beginners) - • DATA STRUCTURES - How ...
Array of Objects Introduction - • Arrays of objects - In...
Dynamic Array of Objects - • Dynamic Arrays of Obje...
Classes and Objects for Beginners - • C++ OOP - Introduction...
Inheritance for beginners - • C++ OOP - What is inhe...
Virtual functions, pure virtual functions, and abstract classes - • Relationship between V...
Polymorphism for beginners - • C++ OOP - What is poly...
CONTENTS:
00:00 - What you will learn in this video?
02:06 - Explaining initial code
03:33 - What is Inheritance?
03:52 - Inheritance implementation
06:48 - What are virtual methods and abstract classes?
09:37 - What is polymorphism?
10:39 - Polymorphism implementation
15:23 - Memory deallocation
16:26 - How to deallocate memory?
17:48 - Static code analyzer
18:35 - Practical task for you
21:18 - Bloopers
🎁 Download PVS-Studio for free & analyze your code: bit.ly/PVS-StudioFreeCB1
Add me on:
Instagram 📸 - / truecodebeauty
Twitter 🐦- / truecodebeauty
******CODE IS IN THE COMMENTS****** Наука
📚 Learn programming with these Free E-Books ⬇
C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.
Code:
#include
#include
using namespace std;
class Student {
public:
string Name;
int Age;
char Gender;
virtual void study() = 0;// a pure virtual method
};
class ProgrammingStudent : public Student {
void study() {
cout
i have question here,
how can i use destructor to deleted those objects here??
You're an excellent teacher, and have a great gift to explain these complex topics so well. I admire you even more now that I know English is not your native language!
standing ovation for this video, your effort in simplifying these concepts deserves a big round of applause
just wanted to drop a quick shoutout for your video, your teaching style rocks, many thanks
your breakdown of arrays of objects, along with insights into polymorphism and inheritance, has given me a solid grasp on these topics, thank you Saldina
hey there Saldina, your video seriously helped me wrap my head around complex programming topics such as this one, just wanted to say thank you
can't thank you enough for this video, you are truly empowering me on my coding journey. Fantastic instructor
Thank you for the excellent content!
Thanks, watching all these series of videos related to array of objects
Thank you for this insightful lesson your coding videos are incredibly valuable for learners like me.
excelent explanation as always, thank you Saldina
I thought English was Saldina's native language. What IS her native language then🤔?
Bosnian I think. I’ve noticed that younger people in ex Yugoslav countries tend to speak English pretty well though. But obviously it will be noticeable to native speakers (like myself) that it’s not their first language.
i wish there is more instructors like you, thanks
great content Saldina, superb explanation, thx
Hi, can you please make a video about Lybiscovist Substitution Principle? This is deeply related to this topic.
Excellent explanation on inheritance and polymorphism! Thank you so much.
seriously thanks for the videos and all what you've done, I'm studying with all the lists of c++, I have learned all what a I know from you, thank you
Could you possibly delve into the use of different scripting languages like Python and C++ to create a login page?
Your videos are filled with highly inspirational and generous instructions. Thank You Saldina Thank You. You’re by far the best most legendary C++ instructor I’ve ever met over the internet. Be well Saldina. Peace and Blessings through our Blessed Mother.
just what i needed, thank you Saldina
Well it is done. I watched all of the oop lessons here. It was totally a masterpiece. I will do more practice and in a few days I will start data structures playlist in your channel. (maybe pointers as well) Thanks for the all cool informations, It was the best so far I have ever seen, u r great!
I didn't know I could do arrays of pointers for every object I make. This is super helpful thank you so much, learned a lot just from this vid🎉
Hola Saldina también se puede considerar usar un poco el standard de C++ algo asi std::vector combinado con las interfase separadas de la clase Student del ejemplo.
Ver:
#include
#include
#include
using namespace std;
/// Part of library study() ///
class IStudy {
public:
virtual void study() = 0;
};
void print( vector &vecStudent ){
for( auto &student : vecStudent){
student->study();
}
}
/// Fin library ///
class Student{
public:
string Name;
int Age;
char Gender;
Student() : Name{}, Age{0}, Gender{' '}{
cout
superb content, even better explanation
This challenge was awesome fun!
Mine is broken up into 8 different files (prototype header and body cpp files for each class), but here is how the main() looks, and what prints out in console:
#include
#include "monster.h"
#include "dragon.h"
#include "werewolf.h"
#include "zombie.h"
int main(){
Monster* monsters[3];
monsters[0] = new Dragon("Smaug", "Reddish Gold", 50);
monsters[1] = new Werewolf("Fenrir", "Ash Grey", 10);
monsters[2] = new Zombie("Dwight", "Pale", 6);
for (int i = 0; i < 3; i++){
std::coutprintMonster();
monsters[i]->move();
monsters[i]->intimidate();
monsters[i]->attack();
std::cout
🚀✨️✨️
I love ur teaching! When does your Programming course exactly start?
Waiting for your course to make C++ as my native language. I can understand it takes time to make a best course. But still very hungry for that..... :)
please cover full STL of C++ and policy based Data Structure also ( using STL)
After we have deleted the dynamic memory taken up by the three objects - don’t we also need to delete the array students of pointers to the objects?
hey saldina can you talk about class composition vs class inheritance??
Hi Saldina. Do you have a separete video about composition?
Hello saldina, could you please explain opengl and STL in c++ , BTW i just love your teaching skills its Brillant 😍
@CodeBeauty
Need the videos of the c++ in a sequential manner which include indepth concept and also the 10hr course of entire c++ is not including every concept you explained.
Please provide the sequence of each and every indepth concepts of c++>
Don't we need a virtual destructor in the base class?
hey saldina at the end of your video you didn't say student[i] = nullptr; i think in a video of yours you said it was a good practice
Sometime I would like to see you comment on why you like object-oriented programming. I have seen several videos critical of OOP but I don't have the experience to intelligently comment on their viewpoint. I am a retired research engineer with programming experience in imperative programming using machine and assembly language on early computers, and later with FORTRAN, some C, and a touch of BASIC. I had a single class in C++ over 20 years ago but changed jobs to a non-programming environment so I never got a chance to use it. I will note that modern Fortran standards have now incorporated some OOP capabilities, so I am interested in seeing if those capabilities might be useful.
which coding language is used throughout your practical programming course???
hi
Please could you teach me how to build a webbrowser with tabs in it
Please ma'am, i need help
I want to learn OpenGL and i need to link the glfw and glut libraries in order to continue but i am using vsCode and i tried lot's of things on the internet but nth worked.
Please can you help me ?
new => wheww
// This is my funny program to study abstract classes
#include
#include
using std::cout;
const int tempo = 500;
const int camerton = 220;
void Performance(int notes, float* pitch, int* duration)
{
for (int i = 0; i < notes; i++)
Beep((camerton * pow(2, pitch[i] / 12)), duration[i] * tempo);
}
class Instrument
{
protected:
int notes;
float* pitch;
int* duration;
public:
virtual void Play() = 0;
};
class Piano : public Instrument
{
public:
Piano()
{
notes = 7;
duration = new int[notes] { 1, 1, 1, 1, 1, 1, 2 };
pitch = new float[notes] { 5, 5, 12, 12, 14, 14, 12 };
}
void Play() override
{
cout
Amazing👏