C++ OOP - What is polymorphism in programming? (simple example)

Поделиться
HTML-код
  • Опубликовано: 28 июн 2024
  • 📚 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.
    The word "polymorphism" means to have many forms.
    Polymorphism usually occurs when we have multiple classes that are related by inheritance. Because of this, two derived classes can define a method that has the same name, but the different implementation (behavior)
    In this video, I'm providing a simple explanation and example of what I mentioned above.
    This is a very understandable and simple explanation, that I found on the internet, and I want to share it with you:
    If you ask a question like "What is a set?" in the forum topic "Tennis", you'll get one answer and if the forum topic is "Data structures" you'll get an entirely different answer. That's because the people who read these two topics process the same question in different ways. This is basically what polymorphism does!
    👉 Download Visual Assist here: bit.ly/VisualAssistDownload
    (Improves Visual Studio experience by quickly identifying and fixing code errors)
    ☕ 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. You can use the link below 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! ❤️😇
    C++ Object-Oriented Programming playlist:
    • C++ OOP - Introduction... - Introduction to OOP
    • C++ OOP (2020) - What ... - Constructors and class methods
    • C++ OOP - What is enca... - Encapsulation
    • C++ OOP - What is inhe... - Inheritance
    C++ for beginners course: • C++ FOR BEGINNERS (202...
    C++ functions course:
    • C++ FUNCTIONS (2020) -...
    Follow me on other platforms:
    Instagram 📸 - / truecodebeauty
    Twitter 🐦- / truecodebeauty
    ******Initial code is available in COMMENTS and on TrueCodeBeauty GIT******
    github.com/TrueCodeBeauty/Pol...
  • НаукаНаука

Комментарии • 179

  • @CodeBeauty
    @CodeBeauty  3 года назад +29

    📚 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.
    #include
    #include
    using namespace std;
    class RUclipsChannel {
    private:
    string Name;
    int SubscribersCount;
    list PublishedVideoTitles;
    protected:
    string OwnerName;
    public:
    RUclipsChannel(string name, string ownerName) {
    Name = name;
    OwnerName = ownerName;
    SubscribersCount = 0;
    }
    void GetInfo() {
    cout

    • @sunilkumar-ft3nk
      @sunilkumar-ft3nk 3 года назад +1

      What is the use of system (pause);.

    • @dasp125
      @dasp125 3 года назад +4

      @@sunilkumar-ft3nk pauses the program so it doesn’t display the directory address, exited with code 0 and press any key in the console after your programs output.

    • @sunilkumar-ft3nk
      @sunilkumar-ft3nk 3 года назад

      @@dasp125 thank 👍👍

    • @ManMartin
      @ManMartin 3 года назад

      Why it is called protected instead shared for example? Cause it is a property shared by all the objects crested frm the origen class. I dont undestand the names, like virtual.

  • @legolas5684
    @legolas5684 3 года назад +16

    please keep making videos!
    A brighter future waits you!

  • @olivertwist8996
    @olivertwist8996 2 года назад +7

    This is honestly the best conetnt on YT for learning c++. My professor is completely useless and makes everything harder. Sometimes I spend 3 hours trying to understand a concept, then I find one fo your videos and I understand it instantly.
    P.S. When I watch your videos I never skip the ads but I let them run for as long as they run. I know that adsense pays youtubers more when ads are watched in full (or something like that :D ), anyway, THANK YOU!

  • @mytechnotalent
    @mytechnotalent 3 года назад +20

    Like the step-by-step breakdown this is a tough subject and you made it quite easy. Well done Saldina!

  • @jesusguerrero6916
    @jesusguerrero6916 2 года назад +3

    I'm a student's software engineer, and your videos are very helpfully to begin in C++ OPP, thanks for this content, I´m sure You help more than one person.
    Greetings from Mexico !!

  • @connelly6375
    @connelly6375 3 года назад +10

    great series, I have been doing C development for a long time and have always been intimidated by C++ but am loving it now!

  • @trueascendant8733
    @trueascendant8733 3 года назад +12

    Very much appreciate your time and energy you put into your video’s I’m still an absolute beginner, could you please do a tutorial on complete beginners for just C programming language, I love 💓 the way you teach you have the best videos on c++ that I’ve seen so far thank you x

  • @dalerobinson3091
    @dalerobinson3091 3 года назад +18

    Hello Saldina. Your videos are very well done, and informative. Would you make a video explaining the 'Copy Constructor' when, and why it is used and needed? Thanks in advance.

  • @humanR14k
    @humanR14k Год назад +5

    For people who didn't understand why Saldina used the pointer at the end of the video, well, I will explain the difference.
    The only limitation in using *yt1 and *yt2 instead of cookingYt and singersYt is that both *yt1 and *yt2 are of type RUclipsChannel* and therefore we can only use these pointers to refer to the members that cookingYT and singersYT inherit from RUclipsChannel. so if we were to call the private function from these derived class (The Function made in these classes), we would use "cookingYT or SingersYT" instead of *yt1 and *yt2.
    thx 😗

  • @gehngis
    @gehngis 3 года назад +12

    That is not polymorphism.
    I mean `CookingRUclipsChannel` has a single function named `Practice`, so their is no need to invoke polymorphism to call `cookingRUclipsChannel->Practice()`.
    Same thing for `SingersRUclipsChannel`.
    So in the end you end up with 2 functions that does not have the same full name: CookingRUclipsChannel::Practice and SingersRUclipsChannel::Practice.
    It is not polymorphism, it is just scoping.
    Casting a pointer of a derived class to a base class is not polymorphism.
    Calling a function a the base class (CheckAnanlytics) through pointer to the base class is still not polymorphism, even if the pointer points to an instance of the derived class.
    To demonstrate polymorphism, you need examples where you are missing a piece of information at the call site.
    You could have done:
    1. Have multiple functions with same name (and scope) but different parameters. This could be done by introducing `CookingRUclipsChannel::Practice(int effort)` and then when calling `cookingRUclipsChannel->Practice()` you effectively use polymorphism because the compiler has to decide if you are calling `CookingRUclipsChannel::Practice(int effort)` or `CookingRUclipsChannel::Practice()`.
    2. Make Practice() a virtual function *and* call it through pointer to the base class.
    class RUclipsChannel {
    ...
    virtual void Practice() = 0;
    ...
    }
    class CookingRUclipsChannel {
    ...
    void Practice() override;
    ...
    }
    RUclipsChannel *channel = new CookingRUclipsChannel;
    channel->Practice();
    3. Use templates and demonstrate polymorphism without inheritance.
    template
    void call_practice(T &channel) {
    channel.Practice();
    }

    • @diezgan
      @diezgan 3 года назад +3

      I agree - without a virtual function (pure or not) in a base class and its overriding in a derived class(es), there is no dynamic polymorphism.

    • @kotinakarwak7857
      @kotinakarwak7857 3 года назад

      Tutor added (simple example) in title and hope she adds the features you mention above in the upcoming lesson to cement the knowledge to us beginners.
      Thanks for pointing this out too since reading through your suggestion easily explains what I have learnt so far and where I should go to next.

    • @jamesperih9658
      @jamesperih9658 3 года назад +2

      I get you on #2 and #3, but either #1 you meant CookingRUclipsChannel() and the base class RUclipsChannel()... or, aren't you just describing overloading?

    • @gehngis
      @gehngis 3 года назад +2

      @@jamesperih9658 Yes, #1 is function overloading. But function overloading is also a subtype of polymorphism, named "ad hoc polymorphism" (en.wikipedia.org/wiki/Ad_hoc_polymorphism).
      I agree though that in day to day developer talks, polymorphism is not used to describe overloading.

    • @jvsnyc
      @jvsnyc 3 года назад

      @@gehngis I strongly agree. Some pedants describe overloading as compile-time-polymorphism or early binding. Many of these pedants are brilliant, and have much to teach me, so I have taken to referring to overloading as compile-time-polymorphism or early-binding polymorphism, but I did OOPS for years without ever describing overloading as polymorphism, we always meant the virtual-method-in-base-class getting overridden behavior via. VTable as the 'simple' definition of polymorphism.
      What she shows is nice, but I normally would not use the term polymorphism there.

  • @jamesperih9658
    @jamesperih9658 3 года назад +14

    Wouldn't it be polymorphism if the base class had a .Practice method, but the derived classes implemented them differently?

    • @jimena6194
      @jimena6194 2 года назад +1

      thats polymorphism as well she has an example of that at the end of her video explaining virtual functions

  • @sayantanpaul6174
    @sayantanpaul6174 3 года назад +4

    Hey Saldina, thank you for providing such great C++ content. Very helpful for non-cs students to enter into programming. Please keep posting more videos. THANK YOU CODE BEAUTY !!😊

  • @pgallovich
    @pgallovich 3 года назад +3

    I’m so glad I followed you from Brads channel. Love this content! So important for me at this time. Thank you!

  • @BetulKaplan
    @BetulKaplan 3 года назад +4

    your video layout is helping me to understand a lot and the way you explain is very clear. keep it up!

    • @CodeBeauty
      @CodeBeauty  3 года назад +3

      I'm happy to help, thanks! 🤗

  • @rif5164
    @rif5164 Год назад

    You make my life easy! Thanks, Saldina!

  • @scalemodelsworld
    @scalemodelsworld 3 года назад +7

    "I'm going to copy that, so that I don't make a typo"
    Introduces a typo with the copy :))
    Nice and informative videos, btw :)

  • @kwayssa
    @kwayssa 3 года назад +3

    Making the pointer type a base Class type, enables the pointer to only access the functions in that base class only, but making the pointer type a derived class type, enables the pointer to access functions in both classes, base class & that derived class..

    • @jvsnyc
      @jvsnyc 3 года назад +1

      I am not sure, but I normally would only use the term polymorphism to refer to when a base class method gets overridden in one or more derived classes, and calls to that method defined in the base class "automagically" get the derived class behavior due to being defined as virtual in the base class thru the use of VTables. While it is true that the derived class members can also add new methods that aren't in the base class, unless the overridden methods call these in the derived class, that isn't using the base class polymorphically. In Java, all of the methods of a class are 'virtual' by default, placed in a VTable, and get this overriding behavior automatically, unless marked 'final' (Java doesn't even have a virtual keyword), but C++ doesn't do this automatically.
      Had she been calling ->practice() thru a base class pointer then this would have been using polymorphism, but that wouldn't even work here unless it was defined in the base class, perhaps as abstract, and virtual. Checking this now. Oops. Visual Studio wants an update, I'll be back after the reboot!

  • @monoman4083
    @monoman4083 3 года назад +4

    Another great video. Many thanks..

  • @createrankit
    @createrankit 3 года назад +3

    Great video lectures, hope you teach development part in c++ .

  • @aw230012
    @aw230012 Год назад +12

    It's a good demonstration of polymorphism but you can't demonstrate true polymorphism without using the virtual keyword for dynamic binding. A better example would be to have the Practice function defined in the RUclipsChannel class as virtual or pure virtual, then override the Practice function in the child classes. Now, you can use Liskov Substitution to store the child classes as their parent, and still invoke the Practice method with polymorphism due to Practice being defined as virtual or pure virtual. I love your C++ series and thought I'd give some feedback on this one. I forward my students to your page all the time!

    • @mes2009
      @mes2009 5 месяцев назад

      Continue Playlist u find what u talk about

  • @1maruf
    @1maruf 3 года назад +1

    *much-obliged, Sister*

  • @kamceksej5524
    @kamceksej5524 Месяц назад

    beautiful video, very helpful, love it.

  • @giovannimagni3493
    @giovannimagni3493 3 года назад +9

    Great Saldina !! Thx you so much for your effort.
    Just a little question about your example. To be honest, I'm not understanding rightly the reason of the pointer used there.
    I mean that same result could be get using derived class method directly. The derived classes are already instanced and yt1->CheckAnalytics() = cookingYtChannel.CheckAnalytics().
    Am I wrong ? What's the rule ?

    • @dynamic_dharsan3_1xor19
      @dynamic_dharsan3_1xor19 3 года назад +2

      I have the same doubt? Contact me if u got correct answer intimate me on discord @iAmDharsan#6700.

    • @joegongamer8637
      @joegongamer8637 2 года назад

      I'm confused as well. Although this video is a good tutorial, I don't think she explained why we have to use pointers. If I were to guess, it might be to call the subclass methods from the superclass. That way, you don't have to type in different names from the subclasses. I might be incorrect but I think you would get the same results either way. However, I feel like it doesn't add up for the example she used because I don't see how using pointers would be more convenient than without them.

    • @jimena6194
      @jimena6194 2 года назад +1

      while that is correct a better example is at the end of her video on virtual functions.

  • @christygeorge9938
    @christygeorge9938 2 года назад +1

    Hi Saldina,
    Your videos are really helpful,
    In this video ,inside the constructor, you haven't initialized the list type, shouldn't we ideally initialize all the variables, in constructor?
    Or else it might give run time issues in our program right

  • @Shad0wBenny
    @Shad0wBenny 2 года назад +3

    Hi Saldina! Just a quick observation;
    In your title for Video 5, polymorphism is misspelled. Your "editor" (wink) snuck in the letter "a."
    Wow, today is the one year anniversary of when the course was posted,
    meaning, that misspelling has been up there the entire time.
    Now now Saldina, that's. just. criminal. :-) lol!

  • @BrunoAlves-tx4gs
    @BrunoAlves-tx4gs 3 года назад +1

    Great video. Muito bom, execelente didatica.

  • @roros2512
    @roros2512 3 года назад +3

    why do you use pointers to get analyitics? shouln't be the same to use a method? thanks Saldina

  • @naderhumood1199
    @naderhumood1199 2 года назад +1

    Amazing channel......Thanks v much.

  • @ahmadghamsari8603
    @ahmadghamsari8603 3 года назад +1

    I am so glad to see your page accidentally! You are a very good teacher.
    Do you have any idea about using C++ on visual studio for programming micro controllers such as those are ARM based?

    • @connelly6375
      @connelly6375 3 года назад

      It is possible to program for MCU's in visual studio but it can be hard to setup, but it is possible. You can use STM32CubeIDE to develop C++ for ST MCU's, or Atmel Studio for Atmel MCU's, Atmel Studio looks almost identical to visual studio while STM32CubeIDE is based on eclipse.

  • @ashrsfsiliman452
    @ashrsfsiliman452 3 года назад +2

    Thank you for your great job

  • @tharushinehara4318
    @tharushinehara4318 2 года назад

    helped me a lot!

  • @ermiasayele7111
    @ermiasayele7111 Год назад

    thank you very much I learn much much in a few minuet

  • @juanmanueldeayanz1821
    @juanmanueldeayanz1821 3 года назад

    Gracias Saldina!
    ¿Harás vídeos sobre Software Architecture and Design Patterns más adelante?
    Saludos desde España.

  • @charleswahome7936
    @charleswahome7936 Месяц назад

    Great video. If I may ask, there is this concept that method overriding must happen for us to implement polymorphism. And a virtual function must be declared in the base class so that the overriding can be done in the child classes. Is it a must we do overriding of methods in the child classes? Or must we create the virtual function in the baseclass to make it abstract?

  • @nuamaaniqbal6373
    @nuamaaniqbal6373 2 года назад

    Thank You!

  • @madhusankawijerathne8435
    @madhusankawijerathne8435 Год назад

    Than you!

  • @starthustling3290
    @starthustling3290 3 года назад +1

    Thanks

  • @tejasdhule249
    @tejasdhule249 2 года назад +2

    This is my bad luck that I have visited this channel so late .... If I had visited this OOPs series an year before then definitely today I will be working with India's one of best Service Based Wipro Software Company 😓...... Because last year I got a chance for interview in Wipro Software LTD. And the interviewer asked me to implement these OOPs concepts with C++ code examples ..... But I was unable to do so because my concepts were not clear 😭..... Saldina Why don't you meet me an year before 😭

  • @leonardopantoja7121
    @leonardopantoja7121 Месяц назад +1

    Son Interesantes tus videos.

  • @isrza
    @isrza 2 года назад

    Using pointer is exactly what I was looking for. As a student with java experience I stuck about using different type of objects derived from a base class in a single function. Using parameter as a pointer of base class in function is what I needed, thank you so much.

    • @joegongamer8637
      @joegongamer8637 2 года назад

      Do you know why she uses pointers in this video? I ask because I don't think she explained why.

    • @isrza
      @isrza 2 года назад +1

      @@joegongamer8637 She shows how the polymorphism works in C++. Imagine you have a program where it does the exact same function for for all objects but the implementation of these functions is different. In this case you would have create a separate function for each object, but with polymorphism you can use parent class as a type ( pointer form for c++) and then use it for all derived classes.

    • @joegongamer8637
      @joegongamer8637 2 года назад +1

      @@isrza I think I somewhat get what you mean. She did make a good C++ video on polymorphism. However, I still don't think she explains clearly why we would use pointers in this video. So, if she doesn't want to give a better understanding of why use pointers for polymorphism, then can you please provide me a clearer explanation?

    • @isrza
      @isrza 2 года назад

      @@joegongamer8637 well let me give you an explanation about in practice. Imagine we have a a game where you can shoot enemies friends and object ( boxes and etc.). But I you might have guessed each object will give you a different reaction ( enemy will lost health, box will collapse, fried will also lost health but tell you be careful). In this case all these objects have a property call getHit, but have different implementation. But in order to get this property work our bullet objet have to call this property whenever it meet with an object which has a properly getHit. But we don't want to have a long if else statements. Instead we want to use an argument which can represent all hitable objects. Bu beaucoup of the syntax kr nature of C++ we cannot give a parent call as arguments and pass ther child class in use. In order use use polymorphism we have to pass that argument as a pointer, this is something about nature of c++.
      ruclips.net/video/MZOrGXk4XFI/видео.html . This the reference of my explanation. You can take a look if you want. It is c# but focus on the concept than language. As you can see in c# we don't use pointers, neither in java. So usage of pointers is only about syntax of C++.

    • @joegongamer8637
      @joegongamer8637 2 года назад

      @@isrza Although I appreciate your efforts in your explanation, I unfortunately still somewhat get what you mean. What I can understand is how it can make you write less code when you have a lot of objects, loops, and if/else statements to deal with. If using pointers is the only way for the superclass to access the same method from the subclass(ex. Animal tries to call speak() to print out the respected animal sound depending on the type of subclass animal), then I can understand. There are some cases where using pointers is just a personal choice. Her example @13:48 would print the same results even without pointers, just a different way of coding it. The same goes for the GetInfo method because you can also do Animal test = daDog; test.GetInfo(); to get the information about daDog object. If you're dealing with let's say multiple Animal objects, you can create an Animal array. The only things I can understand using pointers when it comes to polymorphism are if it's the *only way* for the parent object to access the same method from its child object OR for the parent object to pass the child object by reference, which would allow the programmer to get and modify its original properties. Other than that, I don't see why else one should use pointers for polymorphism.
      Thank you for posting the link, I'll see if I can check it out as I'm also interested in C#, game dev, and gaming.

  • @xiaonanfan6543
    @xiaonanfan6543 Год назад

    pls can you make some middle sized C++ Project that we can use and practice the C++ knowleadge we leaned from you,thanks.

  • @teprox7690
    @teprox7690 Год назад

    CheckAnalytics is public for both subclasses. Why you need the pointers?

  • @indiangigachad777
    @indiangigachad777 3 года назад

    Hey Saldina, I am going through the book C++ Primer Plus 6th Ed....im stuck on chapter 12-13 dynamic memory alloc, and inheritance...how would you push through in times when you get stuck on a concept?

  • @crazycoder9356
    @crazycoder9356 Год назад

    thanks.

  • @TheDarkLordSpaniard
    @TheDarkLordSpaniard 3 года назад +6

    Hello! Why do we use pointers instead of for example singersYtChannel.CheckAnalytics(); since it's public already. I might've missed something.
    Cheers for the course!

    • @KishoreG2396
      @KishoreG2396 3 года назад

      The pointers are what polymorphism allows us to do: access the derived class through a pointer of the base class.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy 2 года назад +2

      @@KishoreG2396 But why? It's much easier to just type in object name and then invoke the method directly.

    • @KishoreG2396
      @KishoreG2396 2 года назад +5

      @@GauravSingh-ku5xy Because in some cases we want to use more generic behavior.
      For example, let's say you have an Animal class, and all it's derived classes are types of animals like Dog, Cat, etc. If you have an Animal*, you can store any animal in it, so you don't need to worry about it specifically being a Dog, Cat, or something else. You can perform a generic action on an Animal, like Animal::eat() or Animal::walk() without knowing the derived class type.
      Also, you can store an array of multiple different Animal types if it is an array that stores Animal. Let's say you have an array that represents a zoo (Animal zooAnimals[5] ). You could store different types of animals, like 1 Zebra, 2 Giraffes, and 2 Lions. Whereas if the type of the array was just a specific object type, you could only store that single object type like Dog or Cat.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy 2 года назад +2

      @@KishoreG2396 I got it man. That was a good explanation.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy 2 года назад +2

      @@KishoreG2396 Also, so here we are seeing polymorphism in an object (because same pointer can also point to a different object) and also in its function(The function has same name but different implementation). Right?

  • @grosucristi6599
    @grosucristi6599 Год назад

    At 13:20 why did you use pointers to call a method from base class if you can do it directly from derived class?

  • @yashsonawane905
    @yashsonawane905 2 года назад +2

    What is the use of pointer here? I really didn't get it. Can you explain it, please?

    • @joegongamer8637
      @joegongamer8637 2 года назад

      I don't know if she explained it well enough but I think it's for the parent class to access the same method from the child class. You need the Practice method in the parent class cause that's how you can have your child classes get the same method but different implementation. It doesn't make sense if the subclass gets the Practice method while the superclass doesn't cause it's like where did the children get their traits from(they have to get it from their parents). Using her example, let's say you want to store a cooking YT channel(subclass) in a YT channel(superclass). If you try to call the Practice method on this superclass, it won't call the practice method from the cooking channel subclass. Instead, it would call the practice method from the YT channel superclass. This provides an inaccuracy(logical error). The way to fix this is to have the parent object be a pointer object *AND* having the parent method has the code word: virtual(I have yet to figure out why that is). This would let the parent object point to the practice method in the cooking channel subclass, thus, being able to print what a YT cook should practice(instead of what a default RUclipsr should practice).
      Another reason is to pass by reference. If you want to access the original object and modify its properties, then pointers are a must. Hopefully, this explanation helps(idk whether you already found your answer or not).

  • @ruchitechster
    @ruchitechster Год назад +1

    Hey Saldina i'm from India, in my 2nd year of BCA i have C++ but i can't understand anything. Your videos are very easy to understand and so helpful, Thanks a lot :)

    • @kilipkumar
      @kilipkumar 9 месяцев назад

      you are right , I am also doing BCA course in Gujarat . i cant speak english rather than can understand all the consepts that saldina explained .

  • @meisam7144
    @meisam7144 Год назад

    Why did you define pointers to access CheckAnalytics? Couldn't you access them through the already defined objects? Great videos btw...

  • @abdallahshihab3106
    @abdallahshihab3106 3 года назад

    please keep making videos .

  • @anonymousbelgique7331
    @anonymousbelgique7331 2 года назад

    thank you vm

  • @JarekAtWork
    @JarekAtWork Год назад

    Without you, I wouldn't be here.

  • @fxsurgeon1
    @fxsurgeon1 2 года назад +1

    Hi, thanks for your great content. Could you explain why you used pointers to the base class instead of invoking the CheckAnalytics method directly from the objects?

    • @ddddd1687
      @ddddd1687 2 года назад

      Hi have you found any answer to your question? Because I am wondering the same thing 😂

    • @fxsurgeon1
      @fxsurgeon1 2 года назад

      @@ddddd1687 I moved to Python and feel much happier lol

    • @ddddd1687
      @ddddd1687 2 года назад

      Hahahah 🤣 OK thanks

    • @day4834
      @day4834 2 года назад

      Hi, I believe this was just for learning purposes, so that we know that a derived class can be called via a pointer in the bases class and a function can be invoked using such pointer.

    • @ddddd1687
      @ddddd1687 2 года назад

      @@day4834 Hi ,thank you for your answer :)

  • @382946rthu
    @382946rthu 2 года назад

    Probably wouldn't have been a bad idea to show what happens when the derived class is cast back to the base class or wait practice is missing from the base class. To be polymorphic shouldn't the base class also have had a practise method?

  • @muhammadaon9147
    @muhammadaon9147 Год назад

    std::cout

  • @erende44
    @erende44 2 года назад

    maybe not so important but you have a typo in the title of this video :) Thank you for your work!

  • @absamurai
    @absamurai 2 года назад

    Hi! There is a typo in the video caption (polymorphisAm).

  • @ronitakhariya4094
    @ronitakhariya4094 3 года назад +1

    why did we use pointers instead of just using
    cookingYtChannel.CheckAnalytics();
    ?
    why create a *yt1 for it?

    • @KishoreG2396
      @KishoreG2396 3 года назад +1

      That's what polymorphism is. The pointer was used because we want to access the derived class instance through a base class pointer.

    • @joegongamer8637
      @joegongamer8637 2 года назад

      @Ronit Akhariya Maybe it's because passing by value won't give you the original results from the CheckAnalytics method. Pointers let you pass by reference which means you can access the original properties of the child object and modify it. Without pointers, you'll affect its copy instead of the original object. Hopefully, I'm correct about this cause I'm still waiting for K G. to confirm if this reasoning is correct.

    • @KishoreG2396
      @KishoreG2396 2 года назад +1

      @@joegongamer8637 Check the comments of the previous thread. I posted a reply

  • @Itsme1n1ly
    @Itsme1n1ly 2 года назад +1

    Queen of C++

  • @uguryucestudent281
    @uguryucestudent281 Год назад

    What happened if we do not use polymorphisam?

  • @asadkhan-zg3rn
    @asadkhan-zg3rn 3 года назад

    ma'am can you please make tutorials of JavaFX..!!

  • @Dani-mp2we
    @Dani-mp2we 3 года назад +1

    I dont understood. Why do you deal with pointers in this video? Is that extra? Or are there in context with the polymorphismus?

    • @KishoreG2396
      @KishoreG2396 3 года назад +2

      The reason we use pointers is because we are trying to access the functionality through the base class. So we create a base class pointer, but we set it equal to the address of a derived class instance. Thus, the same pointer can be used to refer to any derived class instance. That's what polymorphism is.

  • @marathirada1199
    @marathirada1199 2 года назад

    Pls send code of this tutorial in description

  • @noorallahpayanda
    @noorallahpayanda 3 года назад +1

    why do you not have a video for the structure in c++

    • @CodeBeauty
      @CodeBeauty  3 года назад +1

      Hahaha, I just didn't find time to create it so far. Thanks for showing interest 🤗

    • @noorallahpayanda
      @noorallahpayanda 3 года назад

      @@CodeBeauty thank you from your response

  • @smpbih
    @smpbih 3 года назад +2

    prelijepa si

  • @siddharthasarmah9266
    @siddharthasarmah9266 3 года назад +1

    Can you please increase your video sound. Really like your tutorials

    • @CodeBeauty
      @CodeBeauty  3 года назад +1

      I can try 😊
      What do you think about the sound quality of this video ruclips.net/video/42t2-6Tqy0U/видео.html
      Is it any better? 🤔
      I tried to increase the sound a little bit in that video, but I didn't want to increase it too much, because then you can hear my air conditioner buzz in the background 😒

    • @siddharthasarmah9266
      @siddharthasarmah9266 3 года назад +1

      @@CodeBeauty yah the second one is much better😃😄

  • @yashpatil9247
    @yashpatil9247 3 года назад

    why there is a need to initialize constructor of parent class in every inherited class

    • @joegongamer8637
      @joegongamer8637 2 года назад +1

      If I understand what you're trying to ask, it's required for the subclass' constructor to be initialized from the superclass. It's kinda like without the child having inherited traits from the parents, the child wouldn't exist.

  • @rwagasanaelisa1379
    @rwagasanaelisa1379 9 месяцев назад

    you speak understandable language
    but i request you to do mre examples for better understanding

  • @arjunans5139
    @arjunans5139 5 месяцев назад

    If you have watched previous videos , click 2:57

  • @Brusselsprouts2023
    @Brusselsprouts2023 2 месяца назад +1

    Saldina here!! to rescue again!!

  • @pranavkotesh.v7556
    @pranavkotesh.v7556 3 года назад +2

    Im here from freecodecamp. And god your gorgous!

  • @zihadFromPhero
    @zihadFromPhero 3 месяца назад

    is that actually polymorphism ??
    the two function is independent on their own way. they are declared in the 2 independent derived class.
    in my knowledge polymorphism is a process to override the data. so that compiler can handle different function with same name and decide that what function should run.

  • @kikosmiletv4531
    @kikosmiletv4531 Год назад

    new subscriber here, how can you be so intelligent and very pretty at the same time?

  • @konstantine3466
    @konstantine3466 3 года назад

    Polymorphism... As say in our Odessa: explain kroz dupe. Oh, women. Saldina, you're so bloody irresistible!

  • @debjyotinandi9140
    @debjyotinandi9140 2 года назад +1

    Amy reminds me of the owner of Amy's bakery from Kitchen Nightmares

  • @SILX
    @SILX 2 года назад +1

    btw, you spelt polymorphism wrong in the title

  • @JarekAtWork
    @JarekAtWork Год назад +1

    Sometimes I think you're not real. No computer scientist changes their clothes so often.

    • @CodeBeauty
      @CodeBeauty  Год назад

      Hahaha, very much real and fancy 😅🥰

  • @fusiontv5269
    @fusiontv5269 3 года назад

    11:18

    • @joegongamer8637
      @joegongamer8637 2 года назад

      Yeah, I think using pointers for polymorphism should be a burning question for her OOP in C++ video.

  • @amaanmajeed4068
    @amaanmajeed4068 3 года назад +1

    John Sings

  • @ahasanhabibsajeeb1979
    @ahasanhabibsajeeb1979 3 года назад

    Your pronunciation " PublishedVideoTitles" is aesthetic 😅

  • @GenjaOrigins
    @GenjaOrigins 2 года назад

    cpp overriding vs overloading thats annoying. I thought i knew but clearly i messed things up.
    There is something i that connects that but its different damn.
    Polymorphism is...
    -CompileTime "Static Polymorphism" e.g method overloading
    -RunTime "Dynamic Polymorphism" e.g function Overiding
    But Overloading is either
    -Operator Overloading _Operator overloading is a compile-time polymorphism in which a standard operator is overloaded to provide a user-defined definition to it.
    -Function Overloading _Function overloading is also a type of compile-time polymorphism which can define a family of functions with the same name. The function would perform different operations based on the argument list in the function call. The function to be invoked depends on the number of arguments and the type of the arguments in the argument list.

    • @GenjaOrigins
      @GenjaOrigins 2 года назад

      Method is a bit different from function but we need to say its the same thing. This example that you are using i think its function overriding so its not polymorphim but a type of polymorphism. I think thats what i need understand cause its complicated xd. So i guess polymorphism is just an idea an ability of an object to have many forms maybe and it has different types.

  • @user-td4pf6rr2t
    @user-td4pf6rr2t Месяц назад

    Academia is Hard.

  • @kotinakarwak7857
    @kotinakarwak7857 3 года назад +1

    Please pad the comment for me to understand what that line of code is doing.
    RUclipsChannel *yt1 = &cook01; //assign a pointer to a base class enitiy to an instance of its derived object address.

    • @tombarrett2306
      @tombarrett2306 3 года назад +1

      This line of code creates a pointer for the Type RUclipsChannel then it sets it equal to the address of cook01 via the use of the & (Address operator)

    • @joegongamer8637
      @joegongamer8637 2 года назад

      @@tombarrett2306 The next question I have is if it gives the same result as without using pointers?

    • @tombarrett2306
      @tombarrett2306 2 года назад +1

      @@joegongamer8637 So in response to your question if I understand what you're asking. Pointers are used for referencing things so you can point a pointer at a location in memory and access it. However a pointer is only a reference what it points to determines what will happen when it is dereferenced. The reason to use pointers is it gives you better control of memory.

    • @joegongamer8637
      @joegongamer8637 2 года назад

      @@tombarrett2306 Thanks for trying to understand and explain more about pointers. Pointers are a hard lesson to learn as it took a long while for me to understand them well. I plan on relearning them in my spare time.
      *What I meant to ask was if she didn't use pointers, would the result still be the same at **13:48**?*

  • @nezokochaan3198
    @nezokochaan3198 3 месяца назад

    6:58 😳😳😳😳

  • @shoshanamofaz3012
    @shoshanamofaz3012 3 года назад

    Polymorphic code like hackers use? It’s hard to detect. Great for creating a back door in the network. Bad stuff

  • @tahmid1847
    @tahmid1847 Год назад

    Ilhan are you here?

  • @mercynik2019
    @mercynik2019 Год назад

    why you made everything so complicated like its hard to understand for a beginner in oops like me ..

    • @CodeBeauty
      @CodeBeauty  Год назад +1

      There are 4 videos prior to this one that you should watch. This is part 5. If you watch those video then this should be easy to understand 🤔💡

    • @mercynik2019
      @mercynik2019 Год назад

      @@CodeBeauty ohh thanks i will check them for sure , operator overloading type of polymorphism is too difficult for me
      & I'm searching for it and just find your video...... Thanks for your reply ☺️ hope this will helps me to find 😊

    • @CodeBeauty
      @CodeBeauty  Год назад +1

      @@mercynik2019 check out object-oriented programming playlist on my channel, n watch it from beginning, it goes step by step-by-step 😃

    • @mercynik2019
      @mercynik2019 Год назад

      @@CodeBeauty Got it, thanks ☺️

  • @RakyFX
    @RakyFX 3 года назад +1

    Ohh how beautiful girl

  • @jurekpacewicz2693
    @jurekpacewicz2693 2 года назад +2

    Hi Saldina, I enjoy your lectures. I have got some suggestions for you to master your presentation. The fundamental thing is that you use (unfortunately as many others) the default font size, which is definitely too small. It has to be at least 2 points more, if possible even 3 points. Not everyone has got falcon's eyes. The most important thing is a screen organisation. You put an enormous big banner with your IT addresses. That takes a lot of screen space. That info banner should not be even there or much, much smaller. I enjoy seeing you "Pretty Woman" with your beautiful long hair. Unfortunately it doesn't help to concentrate on lectures, in contrary it distracts an attention a lot. Again it is much, much too big! Try to see your lectures on different screens, from smartphones through notebooks ending on big 30" - 50" screens. The knowledge you give should be given in the easiest and the most readable way. The black screen is the worst readable solution!!!
    I wish you would be the best.
    Zdrowia Radosci i samych PRZYJEMNOSCI from Poland. Jurek, your fun

  • @ivans7
    @ivans7 Год назад

    you complicated the thing. I still don't understand.. :(

  • @madelinelopez2035
    @madelinelopez2035 Год назад

    Hi Saldina - Love your content! 🙂Quick question: what is the benefit to using the "pointer to derived class method" approach over just directly calling the "derivedClass.method()"? In your last example, my first instinct was to use singersYtChannel.CheckAnalytics(). Why use the pointer instead?

    • @saiganeshmanda4904
      @saiganeshmanda4904 Год назад

      I am not an expert but the way I see it, the second method she explained instantiates two objects (of each derived class) from the same superclass (or parent class) rather than invoking the CheckAnalytics() function for two objects defined from each derived class separately.
      So, instead of instatiating objects from child classes separately, the second method did it from instantiation from the one single parent class itself.
      The reason I wondered the same question as you did is because I thought -
      This second way of implementing polymorphism using pointers would also require you to create two separate objects. How is it any better than the first implementation (the one without using pointers)?

  • @azizprimbetov2745
    @azizprimbetov2745 Год назад

    Hello Saldina i have a question why do i need to use pointer checkanalytics method is public we can check it directly using object ytb.checkqualiyt() method

  • @michaelvaland5467
    @michaelvaland5467 Год назад +2

    hey so why can't we just call the check analytics method without having to create a pointer of the base class and calling it directly on the derived class like: cookingYtChannel.checkAnalytics();

  • @lifehealerzr2508
    @lifehealerzr2508 11 месяцев назад

    singers youtube channel does not work.