Practical Polymorphism C++

Sdílet
Vložit
  • čas přidán 2. 07. 2024
  • Polymorphism is a powerful yet potentially confusing feature of C++. In this video I create a simple Computer Aided Design (CAD) application that exploits polymorphism to keep the application simple yet highly customiseable.
    Source: github.com/OneLoneCoder/Javid...
    CZcams: / javidx9
    / javidx9extra
    Discord: / discord
    Twitter: / javidx9
    Twitch: / javidx9
    GitHub: www.github.com/onelonecoder
    Patreon: / javidx9
    Homepage: www.onelonecoder.com
  • Věda a technologie

Komentáře • 234

  • @martinofeldman1039
    @martinofeldman1039 Před 5 lety +236

    You are a very clever guy. And I realized that my brain needs some upgrade...

    • @javidx9
      @javidx9  Před 5 lety +89

      lol thanks Martino :D Download some more brain!

    • @sweetberries4611
      @sweetberries4611 Před 5 lety +22

      @@javidx9 Like, download more ram?

    • @yassine321
      @yassine321 Před 5 lety +5

      U should see the appropriat requirements system for ur old end brain

    • @theternal
      @theternal Před 4 lety +6

      @@javidx9 plz link

    • @ananttiwari1337
      @ananttiwari1337 Před 3 lety +2

      Well, idk about downloading free brain but you can try www.downloadmoreram.com to download more free RAM!! totally works 100% legit free definitely not a rickroll*

  • @willmapleson1023
    @willmapleson1023 Před 3 lety +27

    Your optimistic attitude and thorough explanations make learning new things such a breeze. You are a great teacher. If you ever made a paid C++ beginner to expert course, I would pay big $$$.

  • @leerv.
    @leerv. Před 3 lety +13

    Polymorphism literally means "many shape"-ism, so this seems like the perfect implementation of an example. :)

  • @KingdomBusiness21
    @KingdomBusiness21 Před 5 lety +14

    The amount of appreciation I feel for you and the knowledge that you have broken down in the first 10 minutes of this video is truly unquantifiable. I am blessed to live in a time where I can seek to learn a topic and stumble upon this informaiton on demand and free. I hope that what I received for me is returned to you ten fold! You are very helpful and kind. Thank you.

    • @javidx9
      @javidx9  Před 5 lety +4

      Incredibly kind words Kirk, much appreciated and im pleased you found it useful.

  • @BinkiklouGaminglol
    @BinkiklouGaminglol Před 5 lety +39

    You are very smart, placing the camera infront of the mirror is genius.

    • @kushagra64
      @kushagra64 Před 3 lety +2

      I really didn't realized that :0

  • @KiAb0n0V
    @KiAb0n0V Před 5 lety +14

    @Javidx9 I'd like to thank you for your videos, the way you explain computer science concepts helps me to fill up all the missing knowledge from uni.

  • @orfeasliossatos
    @orfeasliossatos Před 5 lety +2

    The little pause when you cut to real life brings me endless joy, also this is exactly what I was looking for!
    I’m creating a program through which I can run other little programs, but since they all have the same structure (Input-Update-Display) I learned I could have been using polymorphism to create a « subProgram » class and clean up my code.
    Thank you, have a wonderful day!

  • @EmmanuelMayor
    @EmmanuelMayor Před 3 lety +10

    Man, of all the programmers I've been seeing on CZcams, I think you are one of a kind. I'm' finally understanding a lot of things about OOP just by watching your videos. Never thought that OneNote could have another use other than bloat Windows 10, in fact, those are the parts I love the most. Thank you.

  • @arcnaver
    @arcnaver Před 5 lety +3

    This is a heck of a lot better of an explanation than my University class material! You need to do more stuff like this! Thanks.

  • @abhishekgy38
    @abhishekgy38 Před 5 lety +1

    @javidx9 This is top notch, sir. I'm happy I came across your channel.Looking forward to more of these.

  • @rfdave3980
    @rfdave3980 Před 3 lety

    You have explained the concept very well, Dave. It is a difficult thing to get your head around. Thank you !

  • @seebaastian
    @seebaastian Před 5 lety +1

    As usual, the most incredible explanation I ever seen about polymorfism. I hope you were my teacher. Thanks for your videos ;)

  • @ivelinkarageorgiev3111

    I'm growing so much in love with this channel.

  • @leonardochiruzzi7642
    @leonardochiruzzi7642 Před 5 lety +3

    This is just what I was looking for. I've banged my head for years. A million thanks!

    • @javidx9
      @javidx9  Před 5 lety +1

      I hope you find it useful Leonardo, its not the easiest topic to deliver via video :D

  • @skilz8098
    @skilz8098 Před 4 lety +1

    Very intuitive! A possible nice feature you could add to this application in regards to the spline or the curve would be the ability to add additional nodes or points after it is drawn. So if the user selects the curve between the 2 endpoints (the beginning and endpoints) the application would then get the point defined by the mouse's position and add that as a new node at that location on the curve. It would then use the previous and next nodes as the two endpoints to generate a new curve on the existing curve. Another rich feature would be able to create an arbitrary polygon from multiple lines. When creating multiple lines, if two points coincide you could allow the user to have the option to combine those multiple points into a single point. The arbitrary polygon would not be created unless if it is entirely enclosed, otherwise, you would just have a list of lines with connected vertices.

  •  Před 2 lety

    This is one of the most inspiring and edutaining videos. I revisit it every now and then :)

  • @sunlighthurtsmyeyes9269

    I've started learning OOP lately and this video helped me a lot, thank you very much

  • @YoomarTuNoOmar
    @YoomarTuNoOmar Před 5 lety

    Thank you very much programming wizard, this is exactly what I needed. I am planning to do a WindowsForm-Like application for some school project using olcConsoleGameEngine, but got overcome by the C++ polymorphism syntax. Now I know how to get over it.

  • @delofon
    @delofon Před 4 lety +1

    I think I now understand inheritance and polymorphism, at least, a bit better (finally). Ty for educating us all!

  •  Před 5 lety +11

    Another great video, Thanks :)
    a small issue: the zoom in and out factors are not reciprocals (1.1 and 0.9). So, once you zoom in you will not return to the same screen by unzooming. Of course, it’s not critical for a tutorial :)

  • @personsname0
    @personsname0 Před 4 lety +5

    This really cleared up a few things from my OOP class (even though it was taught in Java), cheers mate!
    BTW, did I hear you say that you were going to do more assembly and FPGA?!? ;)

  • @AnalyzeForSafety
    @AnalyzeForSafety Před 3 lety

    Wow, just wow... this tutorial is sooo cool!
    Thank you, really thank you!

  • @kamaladdinahmadzada9965
    @kamaladdinahmadzada9965 Před 5 lety +1

    Another great video again Thank U!

  • @ValeriCFBG
    @ValeriCFBG Před 3 lety

    One thing that I learned from watching those is that it may feel intimidating to understand the math in the speed of the video, but when you actually sit down and think about those (takes me 1-2 hours) you start going "Ohhhhh....that makes sense!"
    Keep it up, amazing stuff!

  • @racorescript
    @racorescript Před 5 lety

    OOB is like wine: enjoy with moderation, which is exactly what you did so, yet again, please accept my compliments.
    Those are by far, in my opinion, the best videos about programming i saw on CZcams. Since you have an established audience of people who wants to learn some serious programming, you may consider to extend this topic talking about templates at some point. After all, why do something at run time when it can be done at compile time, right?
    Keep up the great work. Looking forward for the next episode of the top down city games. Bye

  • @jsflood
    @jsflood Před 5 lety

    Great video! The phase was perfect :-)

  • @juliankandlhofer7553
    @juliankandlhofer7553 Před 4 lety

    wow those 40 mins went by very quick!
    great tutorial :)

  • @SaifUlIslam-db1nu
    @SaifUlIslam-db1nu Před 5 lety +1

    My friends around me talk all the time about how to implement graphics onto the console ( we use Dev C++ ), how to develop actual practical applications instead of small management systems; and that's what most of us actually do, prepare small hotel/bank/transportation management systems and just say this is our semester's project.
    But you have made implementing and working with graphics quite intuitive, I understand a lot of why some things are happening, and I can explain why they are happening. This series that you have offered us students has helped me to greatly improve my logic, far above websites like Hacker Rank ( ask any freshmen in my Uni about where to go to improve your problem-solving skills, they say Hacker Rank :/ ). I have learned quite a lot from you, and I can confidently say that if I had sat down to think of the magnitude of the problems which you have dealt with, it would take me some weeks to actually write some something small and applicable. I'm not even confident after watching some of your videos if I can make my things by just looking at your code, though I expect that I should be in the future.
    This is how programming should be taught, dealing with tough problems by breaking them into small pieces.
    Thank you so much. When I get a job, I'll be sure to contribute to you! :)

    • @javidx9
      @javidx9  Před 5 lety +1

      Hi Saif, such kind words, and much appreciated words. I'm very pleased you are finding the videos helpful. Thank you, and good luck with your studies!

  • @Janokins
    @Janokins Před 5 lety +2

    That bit about the classes becoming abstract because of the pure virtual functions - and the fact that they can't be made into objects, has really clarified a lot for me. Thanks

    • @javidx9
      @javidx9  Před 5 lety

      Good stuff Matthew, this is a really high level look at OOP potential, so Im pleased its helping out!

  • @WizardOfArc
    @WizardOfArc Před 5 lety +1

    This one is lovely!

  • @janousekpetr6843
    @janousekpetr6843 Před rokem

    Great video, I absolutely loved it! However, if anyone else is getting SEGMENTATION FAULT ERROR, notice that at 27:35 line 98-100, javidx9 mentions you need to assign *selectedNode to nullptr => but also assigns nullptr to *line. I believe it's not mentioned but it is visible at 29:58.

  • @DeepFriedOreoOffline
    @DeepFriedOreoOffline Před 7 dny

    In an ecosystem where people generally hate object oriented programming because they've had bad experiences making structures before they know what they need, it's nice to see good videos explaining how to do it better!

  • @conor63
    @conor63 Před 5 lety +1

    this is excellent! i was just about to post on discord for some advice cause ive been stuck with polymorphism for a while!

    • @javidx9
      @javidx9  Před 5 lety

      lol Conor, you can post anyway! Easier than discussing via you tube for sure!

  • @onogrirwin
    @onogrirwin Před rokem

    shoutout to that snazzy telephone on the nightstand. To it, C is a brand new high level language.

  • @federicopueblalarregle5791

    Great video! Thank you very much.

  • @greatbullet7372
    @greatbullet7372 Před 5 lety +3

    I need to give you a huge thanks for your c++ videos, im currently in transition to earn money with my selftaugh knowledge. Your Videos give me a roundup on a decent level

  • @ijudgeanime
    @ijudgeanime Před 5 lety +5

    I don't even program anymore but your videos are still entertaining! keep it up :)

    • @javidx9
      @javidx9  Před 5 lety +2

      Thanks buddy, much appreciated! Though you should start programming again!

    • @ijudgeanime
      @ijudgeanime Před 5 lety +1

      @@javidx9 haha I actually majored in programming but I only occasionally do some web development as of recent. I decided to further my career in the more creative path so now I do a lot of designing and concepting but the logical thinking you get from programming still lingers within me XD. That and the fact that I am constantly thinking how my concept for a freaking pop-up store might have bugs in it so I'd better test it..... even though it is a drawing. Probably never gonna lose that haha

  • @johnernest8109
    @johnernest8109 Před 2 lety

    This is really interesting. I've been wanting to make a 3D CAD program for a while somewhat like Rhino3D that handles things like variable fillets.

  • @juliocesarchavezflores1684

    This example is awesome. I was wondering how CAD software works under the hood because I have worked in the development of some scripts to automate stuff on that kind of software but never had a chance to see how it could be developed from scratch and I really want to be involved in the development of open source softwares like FreeCAD or blender. Pretty neat, thanks for share it.

  • @tomkirbygreen
    @tomkirbygreen Před 5 lety +1

    Top video sir. Hope the Road Warrior lifestyle doesn't wear you down too much.

    • @javidx9
      @javidx9  Před 5 lety

      Cheers Tom! Hopefully its all done with for a few months now

  • @streetfashiontv9149
    @streetfashiontv9149 Před 3 lety

    That pixel game engine is epic i hope you can market it some more so it gets the exposure that it deserves like godot etc. Well done this is your seminal work...

  • @ac11dc110
    @ac11dc110 Před 3 lety

    a full featured CAD software! wow!

  • @imuny6579
    @imuny6579 Před 3 lety +2

    Why man so smart?
    Btw, love all of your content 😁👌👍

  • @mohammadmahdifarnia5358

    Oh my god, I haven’t seen anyone like you before in cpp
    1m 👍

  • @streetfashiontv9149
    @streetfashiontv9149 Před 3 lety

    That looks like a hotel room....hats off to you if that's your room it looks immaculate!

  • @andrewminai6094
    @andrewminai6094 Před 5 lety +1

    Love your channel

  • @l0gikk
    @l0gikk Před 5 lety +1

    My left ear loved this

  • @petercsala
    @petercsala Před 5 lety +4

    You knew it deep down, I was gonna be here

    • @javidx9
      @javidx9  Před 5 lety +3

      I feel you are always with me buddy!

  • @juancasadoballesteros
    @juancasadoballesteros Před 5 lety

    Great video as always!!!!
    Lately I have been working on an algorithm from which i would love to see your approach. You might not be interested on it and that wold be fine but lately this problem has been the main thing on my mind so i am still recovering of only talking about it. The algorithm gets the curve created by a 2D plane intersecting the shape inferred from a bunch of 3D points over a grid.
    The points represent Signal loss over a 2D plane and the intersecting planes are the threshold that determine the category of the signal quality. On another words there are a lot of dots with the shape of little mountains and the need is to get the points that determine the curve that the function that could have generated the points wold have made on a plane on the threshold height with as much accuracy as posible.
    Thanks in advice if you comment back on me.
    PS: a video about your approach of the problem would be amazing :D

  • @kksrinivas24
    @kksrinivas24 Před 4 lety +1

    These videos are so helpful. Thanks a lot. I wish we have auto like for all your videos....

  • @soethihanaing123
    @soethihanaing123 Před 3 lety

    Greate Video

  • @mmx555
    @mmx555 Před 5 lety

    @javidx9, You are a mentor to me.
    thank you.

  • @amberheard2869
    @amberheard2869 Před 5 lety

    I am happy that I am soon going to learn polymorphism.I am now on inheritance page (pg 500) and yeah you were right learning programming is by programming not only by reading books I found when programming in compiler I could read and understand them(code) and compile them in my head but when it is my turn to program in c++ I do silly mistakes ex: 1)function with no return type 2)forgetting about scope 3)forget to make warnings ex:catching exceptions for error (like when calculating 1/0) 4)Doing inf loop(forgetting anout condition) 5)range error and many more silly errors.I mostly do syntax error.I forget to mention my biggest mistake was forgetting to insert file for ifstream I just type string for it.I had hard making calculator that was tricky part.There are alot of interesting things happening when doing some programming project.I wish I will progress soon So that I can also do robotic stuff(which was my dream).It is fun (being::geek|nerd).I love your video it encourages me to do programming.I hope to become great mathematician programming is one of the way to excercise my brain for probem solving and thinking form different prespective.

  • @MellexLabs
    @MellexLabs Před 5 lety +2

    Would be very interesting if you could cover design patterns within this application and discuss how relevant they are within OOP...

  • @videomashup2759
    @videomashup2759 Před 5 lety +1

    If you are ever out of ideas on what topic to cover... a code-it-yourself simple programming language and compiler would be awesome!

  • @renderfuture6152
    @renderfuture6152 Před 3 lety

    coool! nice

  • @NeilRoy
    @NeilRoy Před 5 lety +49

    Very nice explanation. I'm still more of a straight C man though.

  • @TylerMatthewHarris
    @TylerMatthewHarris Před 5 lety +4

    Could you do a video about coding the Fourier Transform?

  • @revealingfacts4all
    @revealingfacts4all Před 5 lety +2

    virtual public functions goes against advise of other professionals because it encourages one to redefine the public API, i.e. change the contract, through overloading where the idea is you simply want the same API or contract but with different functionality. You can pull this off by keeping the public functions non virtual and having them call virtual private methods like you describe in this video. This is called the NVI (Non Virtual Interface) pattern. See Scott Meyer's non virtual interface pattern or Herb Sutters article called "virtuality." Otherwise, great video and material!

  • @alfiewhitson7726
    @alfiewhitson7726 Před 5 lety

    @javidx9 really interesting video, very enjoyable however could u in future put a bit of de-esser on your audio in post because the white noise occuring when you pronounce the letter 's' is practically sawing my eardrums in half

  • @conkerconk3
    @conkerconk3 Před 4 lety

    if some want some hefty polymorphism, check out c# wpf. A button inherits a ContentControl which inherits a Control which inherits a FrameworkElement which inherits a UIElement which inherits a Visual (a drawable 'thing') which inherits a DependencyObject which inherits a DispatcherObject (UI stuff isn't very thread safe).

  • @heliosgames6665
    @heliosgames6665 Před 3 lety

    Hello Javidx9, small question about your GetNextNode function, why use vecNodes[vecNodes.size() - 1] instead of vecNodes.back(); ? both should give the same result ? so does this mean its purely for ease of reading the code?
    thank you for your videos,

  • @__hannibaal__
    @__hannibaal__ Před rokem

    Hi. A big things start from small thing; Thanks.

  • @ruben6284
    @ruben6284 Před 5 lety +5

    At 8:05 I believe there must be an arrow operator (->) instead of a dot, because it is a pointer. But this is a great video, I learnt a lot!

    • @javidx9
      @javidx9  Před 5 lety +3

      Thanks Ruben, yeah, its an ad-hoc pseudo scribble, though I should perhaps be more clear in the future!

    • @ruben6284
      @ruben6284 Před 5 lety

      @@javidx9 I think most people will understand what you were doing. Great videos, keep up the good work!

    • @cyberpanda8813
      @cyberpanda8813 Před 5 lety +2

      ​@@javidx9 Actually I'm learning C++, and i wonder how to draw in it in an easier way, thanks man! //Comming from C# -> Java and now C++ wish i've learned c++ first, this language is so AWESOME!

    • @khanhchung4103
      @khanhchung4103 Před 5 lety +2

      trick pa Hey, why dont you check Chili C++ tutorials? He is also very awesome.

    • @cyberpanda8813
      @cyberpanda8813 Před 5 lety +1

      @@khanhchung4103 ​ khanh chung Thank you! I didn't knew him, YES also awesome and hilarious sometimes hahaha, you kept that promise! THANKS

  • @robertboran6234
    @robertboran6234 Před 5 lety

    Also is there any code automation tool for C++ to somehow generate based on a goal (set by the programmer) and a based class a polymorphic scheme using AI ? Or if you already have code but you don't use polymorphism to somehow automatically generate a polymorphic version of your code ?

  • @eformance
    @eformance Před 5 lety

    I'm disappointed we didn't see Superman running around in the background!

  • @1m2u3s8
    @1m2u3s8 Před 4 lety

    grazie

  • @jgcooper
    @jgcooper Před 5 lety +1

    Could you do a video telling us about your chromebook?
    What are the specs, what OS and environment are you using? (how did you set it up)
    What is it able to do, and what do you use it for?
    I was under the impression that they were just web browser machines, and I'm a bit intrigued now.

    • @IgnoreSolutions
      @IgnoreSolutions Před 5 lety

      It is possible to run a full Linux DE inside of ChromeOS. I've done it before on a first gen ARM Samsung Chromebook, it's not very practical or useful but it's something. I have yet to see one running windows.

  • @drcongoheartofafrica7175
    @drcongoheartofafrica7175 Před 5 lety +1

    Javidx9.. thanks a million for this video. it has cleared a lot for me for what I want to use C++ for. I use CAD software packages a lot in my job and wanted to have a pet project designing a Railways/Road alignment CAD package. I need to understand how to draw shapes (lines, circular curves, transition curves, parabolic curves and how to join them up and perform calculations). can I do this without a Kernel ? I'll tell you 10 years from now if I get anywhere near replacing my current engineering CAD package...Top man

    • @javidx9
      @javidx9  Před 5 lety

      lol DRCongo, drawing shapes is not too difficult, most graphics libraries will have more than enough for you, but if you want to do things the hard way, you can always check out Bresenhams Line and Circle Drawing algorithms - a great place to start.

  • @Spartan322
    @Spartan322 Před 5 lety +2

    Aren't you suppose to delete the pointers within the vector? (or list) (lists and) vectors don't destroy pointers and while it is a small program, isn't that still bad practice?

    • @javidx9
      @javidx9  Před 5 lety +1

      Of course you should delete pointers, but in this small demonstration i have no scope for doing so as i dont capture the exit condition, nor do i give the user any facility for removing objects. Since the only sensible exit in the demo shown is process termination, ill let the OS handle it.

  • @minecraftermad
    @minecraftermad Před 3 lety +2

    I first read that as practical polytheism and was just slightly confused

  • @jragomaster25
    @jragomaster25 Před 5 lety

    nice, maybe in a future video add an exporter to .svg?

  • @Magikookeven
    @Magikookeven Před 4 lety

    Like!

  • @just_epo
    @just_epo Před 4 lety

    big brain time

  • @orangasli2943
    @orangasli2943 Před rokem

    @28:52
    Ok now I understand I need to pass this

  • @joshinils
    @joshinils Před 5 lety

    seeing you write out "The End" made me think of a question i had for a while:
    how does a pdf work?
    how is the information that is to be displayed encoded and how is it then displayed?
    i can encode text, images, scalable vector images etc. and i have done so to some extent with LaTeX.
    some of those things i generated are not standard elements of any form. how does my printer then know how to print the same thing the way i defined them and saw them on my screen?

    • @UberMun
      @UberMun Před 5 lety

      PDF is a fancy wrapper for a thing developed by Adobe called PostScript. Modern printers have built-in post-script interpreters to comply with Adobe's standard.

    • @joshinils
      @joshinils Před 5 lety +1

      ​@@UberMun right, which is apparently a turing complete language in itself...
      so making an interpreter for PostScript would be more than an afternoon project

    • @Nohbdy_Ahtall
      @Nohbdy_Ahtall Před 5 lety

      I recommend looking into "LaTeX"! I recently learned a lot more about this world. The simplest I can kinda explain it is rather telling you what I used. I downloaded a program called "Lyx" which also required me to download/install "MiKTeX". Lyx seems decently easy to understand, and you can see the "code" of the document as you write it.
      Anyway, it has like... multiple types of PDF-isms which turn this code into PDF, however it also turns it into HTML or word-like document, etc. I think simply using this made me understand PDFs better, but especially about typesetting and how one would actually write a book.
      Lots of layout-oriented thinking involved ,or - perhaps it is recommended you "don't" think about it, it seems the point of this stuff is partially so you can just focus on the content of the book, not the layout.

  • @oleksijm
    @oleksijm Před 5 lety

    Why am I watching this, I can't even code..
    Or well, I can't yet, but want to learn to. Thanks for this interesting video.

    • @rj-nj3uk
      @rj-nj3uk Před 4 lety

      @saladnuts start with assembly programming 👹

  • @tomay3000
    @tomay3000 Před 4 lety +2

    Where to get the most common and correct names (words) often used when creating an application?
    For example I would have used : "dot" instead of "node" because I am not a native english speaker.
    And that's I also do care about code quality when sharing it.

    • @javidx9
      @javidx9  Před 4 lety +1

      Hmmm. Thats a very tricky and interesting question. To my shame i can only speak English, so this is something ive never considered before...

    • @matheusmarchetti628
      @matheusmarchetti628 Před 3 lety +1

      Kinda late, but I hope it will still be useful. If you're developing an app that represents something real, do a Google search about the real thing and learn how other countries calls things. As a brazilian engineer, I have to do it all the time, and I can deeply relate to your comment

  • @acho8387
    @acho8387 Před 3 lety

    Thank god you're not in your usual setup. Now your neck can get a breather.

  • @Ownage4lif31
    @Ownage4lif31 Před 5 lety +2

    So I barely program in c++ but I have a question. Because in c++, using the new keyword allocates memory to the heap. I don't really see the memory being deleted here once used, unless this is handled internally by your game engine?
    I've not been able to look at the actual code since I'm not home atm. I'd just like to understand this a bit more. Just so I know I'm on the right page.
    Other than that, this video helps me a lot!

    • @javidx9
      @javidx9  Před 5 lety

      As this is just a demo, and there is no facility to remove objects, there is little need and more accurately no sensible place to delete them. Any claimed memory is released when the process exits. Extending the demo to support more tools such as delete would then give you such options.

    • @Ownage4lif31
      @Ownage4lif31 Před 5 lety

      javidx9 OK cool. Thanks for the reply. Makes sense now!

    • @climatechangedoesntbargain9140
      @climatechangedoesntbargain9140 Před 5 lety

      why not just default to make_unique()?

    • @javidx9
      @javidx9  Před 5 lety

      In this instance it doesnt give me anything over and above whats already there. ie the process will terminate before there is opportunity to descope any smart pointers. But also, if i were to add additional functionality, i may want multiple ownership of the object to facilitate grouping, copy and paste etc, undo etc.

    • @climatechangedoesntbargain9140
      @climatechangedoesntbargain9140 Před 5 lety

      ​@@javidx9It does not give you anything more in this case, but it also does not take anything from you, right now. Regarding the additional functionality: Currently you don't have that functionality, and as soon as you have it, you can still "upgrade" to shared pointers if needed. In this case, defaulting to UP even helps you, since you will run into problems faster.
      Thus, it will help you in the future: Less risk of memory mismanagement, less work in the future (when you have to switch and refactoring in case you forget thinking about ownership).
      I don't know why you would not want to default to UQ.
      PS: For copying (shapes) you probably want to have a real copy instead of shared ownership ;)

  • @BradenBest
    @BradenBest Před rokem

    23:20 yes I would agree that &ptr[offset] is bad, at least when ptr[offset] is equivalent to *(ptr + offset), because you could write it as just `ptr + offset`. You can't do that with C++ vectors, so in my opinion, `&vec . at(idx)` is MUCH preferable to `&vec[idx]` because it makes it very clear what is happening and can't be mistaken for a dereference + reference, meaning it's less likely to be mistakenly refactored or even thought about. &ptr[offset] is just asking to be rewritten (or thought about being rewritten) as ptr + offset, because in the general sense, [] and & cancel each other out. And if that breaks the code then it's on you for writing expressions that look like they can be simplified.
    Rant time.
    Honestly operator overloading is one of C++'s worst features. I have a lot of problems with C++, but the two biggest things that I hate about C++ are operator overloading and the programmers that saturate the language who don't know what they're doing, universally insist that C++ is a superset of C when this is demonstrably false, and seem to think they are experts because they can write C++. Not even good C++. Just the fact that they can write a 400 line spaghetti main function that spits out 40 different compiler warnings _but runs_ is enough for them to think they are an authority.
    But lets focus back on operator overloading, because I really want to illustrate why it frustrates me. It sounds like a good idea in theory, but in practice, it's used for horrible things like left shifting a value somehow being synonymous with inserting its string representation into the lhs file (std::cout

  • @factory_enslavement
    @factory_enslavement Před 3 lety

    What's the name of the track from the video called "How a glock works"

  • @trafficface
    @trafficface Před 5 lety

    I am surprised to say I have stayed in nicer hotel rooms for work. But I drew the long straw and got the room with 2 double beds 🤣

  • @BradenBest
    @BradenBest Před rokem

    C does not have polymorphism, but I could still think of an elegant way to handle similar classes of data
    enum shape_type {
    SHAPE_RECTANGLE,
    SHAPE_SQUARE,
    SHAPE_CIRCLE,
    SHAPE_POINT,
    SHAPE_END
    };
    struct shape {
    enum shape_type type;
    double coords[2];
    double sides[2];
    };
    static char const *shape_type_str[SHAPE_END] = {
    "Rectangle",
    "Square",
    "Circle",
    "Point",
    };
    static int (*shape_draw_methods[SHAPE_END])(struct shape const *shape) = {
    shape_rectangle_draw, // static int shape_rectangle_draw(struct shape const *shape)
    shape_rectangle_draw, // we can reuse
    shape_circle_draw,
    NULL,
    };
    void
    shape_draw(struct shape *s)
    {
    // common code goes here
    if (shape_draw_methods[s->type] == NULL)
    return; // no method to call, we're done
    if(!shape_draw_methods[s->type](s))
    // a method returning 0 is a handy way of indicating failure to the caller
    }
    static inline double *
    shape_radius(struct shape *s)
    {
    return s->sides;
    }
    And that's the basic structure. It's certainly a different design pattern. Instead of inheriting from a base class or creating a state machine/switch, we factor out the differences into their own functions and have a generic function do all the common stuff and just call the relevant function. We can define a single function for drawing a rectangle and take advantage of the fact that a square IS a rectangle to just reuse the same function, and then for shape types that don't need to add their own special behavior, we can just set its function pointer to NULL. Even in a language without polymorphism, clean modular design is still very much possible ;)
    I threw the shape_radius function in to show that we don't need to stuff a million properties into a struct or overcomplicate things with unions (although a union is a valid way to assign multiple mutually exclusive types and names to the same space, and simply agreeing that a circle's sides[0] is its radius is valid, too). We could just get the pointer and call it the radius. If the shape code is meant to make shapes a mostly opaque type, we can get away with things like this, because it's not the caller's business to know how the radius is defined, but then on the implementation side, we have a consistent language for what constitutes the radius.

    • @ShadowRadiance
      @ShadowRadiance Před 9 měsíci

      if instead of prefixing the data in `struct shape` with a typecode, you had a "type info" and a pointer to an array of function pointers (for the virtual functions of the class), and set up each Line as being a Shape with a type id of Line and pointer to the "Line table of virtual function pointers" (call it a vtable), you'd basically have what c++ is doing behind the scenes for you.
      That is, implementing a per-class vtable (if virtual functions exist in the class) and sticking the type information (for dynamic-casting) and a pointer to the vtable as a prefix to the object.
      You'd then call the "right override" by using `pShape->pVtable->pFunction()`.
      Since C structs can be happily cast to any struct with the same members in the same order, voila c++ style polymorphism in C.

  • @anonymoussloth6687
    @anonymoussloth6687 Před 2 lety

    If i have a parent class that has some functionality and then a child class extends it and adds new functions, how can I call those functions at runtime using polymorphism? I know one way is to cast it, but what if I don't know what child to cast it to at compile time?
    For example, if i have a class parent which has 2 children: child1 and child2.
    Child1 has foo() and child2 has bar() and these methods are not available in the parent. I have a function that receives a parent pointer and based on which class that points to, call foo or bar.

    • @javidx9
      @javidx9  Před 2 lety

      You can only call functions on classes for which they are defined. So in short, without casting, you can't do what you are asking. A pattern around this is to store in the base class an enumeration of the type, populated by subclasses at construction. This way you have enough "reflection" to determine which cast to use, though caution, this could indicate a flaw with your encapsulated design.

  • @m4rt_
    @m4rt_ Před rokem

    luckily ive used java in the past, so I already understand this :)

  • @hound4425
    @hound4425 Před 5 lety

    Shouldn't at 8:20 be Objects[2]->DoSomething() instead of dot as it's a pointer?

    • @fredhair
      @fredhair Před 5 lety +1

      Pretty sure square brackets dereferences the pointer much like using -> or (*ptr). member. At 23:31 you can see he uses the & (address of/ reference operator) in front of array[size_t] to return a pointer. E.g. &array[0] gets the address of first element whereas array[0] returns the value of first element. Note passing &array[0] would be same as passing array to a function taking pointer type, and array[0] is the same as *array (first value of array).

  • @ashrasmun1
    @ashrasmun1 Před 5 lety +3

    This is DYNAMIC polymorphism. You can use STATIC polymorphism to some extent, and it is way more preferable in the realm of game development.

  • @daanielacosta2395
    @daanielacosta2395 Před 5 lety

    At 38:16 i was getting scared, i thought what happened here xD

  • @ashwiniabhishek1504
    @ashwiniabhishek1504 Před 3 lety

    Compiler decides at run time can that happen??, I thought compiler job is to compile

  • @trueverdicts685
    @trueverdicts685 Před 5 lety +3

    javidx9 do you use any other programming language other than C++?
    Also, what languages do you know other than C++?

  • @tmbarral664
    @tmbarral664 Před 3 lety

    @javidx9 As we have probably always a single pge, it would be better to pass the parm once in the constructor rather than to each Draw() calls. Or the same way you used for worldoffset, as static.... but that's not very elegant

    • @javidx9
      @javidx9  Před 3 lety

      Do it however you wish...

    • @tmbarral664
      @tmbarral664 Před 3 lety

      ​@@javidx9 ;) ok, David, of course. But I was thinking about the meaning of this.
      To pass the pge as a parm means that it can be different for any other calls. That conveys the possibility of many pges. That's fine.
      But is it the intention here ? I was supposing no...I may be totally wrong, of course.
      What are your thoughts about it ?

  • @amberheard2869
    @amberheard2869 Před 5 lety

    How to self study computer science plwase recommend me books list plus please sort them I want to learn it from beginning to end

  • @fengwang9752
    @fengwang9752 Před 4 lety +1

    8:19 vecObjects[2] is a pointer to A, how can you vecObjects[2].DoSomething() ?

    • @MattZelda
      @MattZelda Před 4 lety

      It's basically the same as
      A->doSomething()

  • @jamesgrimwood1285
    @jamesgrimwood1285 Před 5 lety

    I've got one of those Chromebooks :)

    • @luismaschietto
      @luismaschietto Před 4 lety

      Is ot good for development? Because all olc videos are recorded on windows. Chromebook uses Chrome OS

  • @MrBoBiNaToR1000
    @MrBoBiNaToR1000 Před 3 lety

    Can anyone explain how the equations at 20:01 work?

  • @k6l2t
    @k6l2t Před 3 lety

    Polymorphism was fun for a while, and then realized it has the cost of losing control of the structure of your program's memory, which I find quite unattractive. Nowadays I'm more of a fan of tagged unions for this kind of thing, since you get polymorphic behavior without losing control of what memory goes where. Modern OOP just doesn't satisfy me anymore...

  • @tarikeljabiri
    @tarikeljabiri Před 4 lety

    Hi Javidx9, i would like you to make something like that but with wxwidgets please. Vector graphics, i want to use them in wxwidgets. 🙏🙏

  • @kuhluhOG
    @kuhluhOG Před 5 lety

    Now a question:
    If wrote something for test purpose:
    #include
    #include
    class A {
    public:
    virtual void DoSomething(int a = 5) { std::cout

    • @TheMrDemonized
      @TheMrDemonized Před 10 měsíci

      Default parameters are not 'virtualized' so if you have a pointer to A, it will print a default param defined in A, 5. If you want to print 6,you need to cast A* to B* via static_cast

  • @MrQcomber
    @MrQcomber Před 3 lety

    Do we not need to delete the nodes created using "new"?