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 $$$.
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*
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.
Man, of all the programmers I've been seeing on TH-cam, 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.
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!
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! :)
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
Good stuff Matthew, this is a really high level look at OOP potential, so Im pleased its helping out!
5 ปีที่แล้ว +12
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 :)
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.
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!
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.
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!
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!
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 TH-cam. 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
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
@@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
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?!? ;)
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.
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.
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).
@@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!
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...
I would just make an array of floats, and an array of integers. the floats hold all the vertex locations, the integers hold operation IDs, index, and length. basically the array of integers becomes a scripting language that renders sections of the vertex array as shapes. You don't need any classes or polymorphism, just a big switch case of operations.
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.
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
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.
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.
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.
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.
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...
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?
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.
I was using polymorphism a long time before I actually knew it was called polymorphism. I just learned about interfaces. Primarily in relation to COM programming. Typical nomenclature from academia that us mere practical programmers don't care much about.
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,
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!
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.
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.
@@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 ;)
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 ?
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.
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
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
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
@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
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.
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.
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
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.
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?
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.
@@UberMun right, which is apparently a turing complete language in itself... so making an interpreter for PostScript would be more than an afternoon project
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.
Wait couldnt you just have a completely abstract class that is filled with virtual functions? Then if you make different subclasses you can put them all into one vector. Im not sure what you would do with that because none of them would be related, but could you?
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).
@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 ;) 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 ?
Nice explanation. I was wondering, is it possible to extend the idea of polymorphism to a higher order so you can have normal polymorphism between heterogeneous code (the parent class has been written in a different language and the child class is written in C++). I just observe that you need to have homogenous code (same language for the parent and child classes to have polymorphism of any type). This homogenous code idea is in every OOP language. Also i think that if you have a core language (ex. C++) and another language (obscure language like an esoteric programming language) then you can make the code more secure by an advance encrypted polymorphic scheme. I am thinking that in a large SCADA application you can exploit polymorphism in a nasty way to infect the code with a relatively small clever virus.
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 $$$.
You are a very clever guy. And I realized that my brain needs some upgrade...
lol thanks Martino :D Download some more brain!
@@javidx9 Like, download more ram?
U should see the appropriat requirements system for ur old end brain
@@javidx9 plz link
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*
You are very smart, placing the camera infront of the mirror is genius.
I really didn't realized that :0
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.
Incredibly kind words Kirk, much appreciated and im pleased you found it useful.
Polymorphism literally means "many shape"-ism, so this seems like the perfect implementation of an example. :)
Man, of all the programmers I've been seeing on TH-cam, 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.
@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.
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!
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! :)
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!
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
Good stuff Matthew, this is a really high level look at OOP potential, so Im pleased its helping out!
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 :)
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.
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.
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!
I'm growing so much in love with this channel.
This is just what I was looking for. I've banged my head for years. A million thanks!
I hope you find it useful Leonardo, its not the easiest topic to deliver via video :D
Very nice explanation. I'm still more of a straight C man though.
I'm a gay C man
haha i see your comments all over the internet
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.
You have explained the concept very well, Dave. It is a difficult thing to get your head around. Thank you !
I think I now understand inheritance and polymorphism, at least, a bit better (finally). Ty for educating us all!
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!
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!
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 TH-cam. 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
@javidx9 This is top notch, sir. I'm happy I came across your channel.Looking forward to more of these.
This is one of the most inspiring and edutaining videos. I revisit it every now and then :)
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
I don't even program anymore but your videos are still entertaining! keep it up :)
Thanks buddy, much appreciated! Though you should start programming again!
@@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
shoutout to that snazzy telephone on the nightstand. To it, C is a brand new high level language.
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?!? ;)
If you are ever out of ideas on what topic to cover... a code-it-yourself simple programming language and compiler would be awesome!
I've started learning OOP lately and this video helped me a lot, thank you very much
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.
As usual, the most incredible explanation I ever seen about polymorfism. I hope you were my teacher. Thanks for your videos ;)
Top video sir. Hope the Road Warrior lifestyle doesn't wear you down too much.
Cheers Tom! Hopefully its all done with for a few months now
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.
Wow, just wow... this tutorial is sooo cool!
Thank you, really thank you!
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).
That looks like a hotel room....hats off to you if that's your room it looks immaculate!
You knew it deep down, I was gonna be here
I feel you are always with me buddy!
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!
Thanks Ruben, yeah, its an ad-hoc pseudo scribble, though I should perhaps be more clear in the future!
@@javidx9 I think most people will understand what you were doing. Great videos, keep up the good work!
@@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!
trick pa Hey, why dont you check Chili C++ tutorials? He is also very awesome.
@@khanhchung4103 khanh chung Thank you! I didn't knew him, YES also awesome and hilarious sometimes hahaha, you kept that promise! THANKS
Would be very interesting if you could cover design patterns within this application and discuss how relevant they are within OOP...
I first read that as practical polytheism and was just slightly confused
Great video! Thank you very much.
Thanks Federico!
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...
I would just make an array of floats, and an array of integers.
the floats hold all the vertex locations, the integers hold operation IDs, index, and length.
basically the array of integers becomes a scripting language that renders sections of the vertex array as shapes.
You don't need any classes or polymorphism, just a big switch case of operations.
a full featured CAD software! wow!
Oh my god, I haven’t seen anyone like you before in cpp
1m 👍
wow those 40 mins went by very quick!
great tutorial :)
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.
My left ear loved this
this is excellent! i was just about to post on discord for some advice cause ive been stuck with polymorphism for a while!
lol Conor, you can post anyway! Easier than discussing via you tube for sure!
Thank very much for this great video
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
Could you do a video about coding the Fourier Transform?
Why man so smart?
Btw, love all of your content 😁👌👍
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.
I'm disappointed we didn't see Superman running around in the background!
These videos are so helpful. Thanks a lot. I wish we have auto like for all your videos....
Thank you Krishna!
Another great video again Thank U!
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.
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.
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.
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.
Thank god you're not in your usual setup. Now your neck can get a breather.
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...
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?
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.
I was using polymorphism a long time before I actually knew it was called polymorphism. I just learned about interfaces. Primarily in relation to COM programming. Typical nomenclature from academia that us mere practical programmers don't care much about.
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,
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!
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.
javidx9 OK cool. Thanks for the reply. Makes sense now!
why not just default to make_unique()?
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.
@@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 ;)
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 ?
javidx9 do you use any other programming language other than C++?
Also, what languages do you know other than C++?
Love your channel
Cheers Andrew!
Hi. A big things start from small thing; Thanks.
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.
Hmmm. Thats a very tricky and interesting question. To my shame i can only speak English, so this is something ive never considered before...
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
This one is lovely!
@28:52
Ok now I understand I need to pass this
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
Now a question:
If wrote something for test purpose:
#include
#include
class A {
public:
virtual void DoSomething(int a = 5) { std::cout
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
Great video! The phase was perfect :-)
Compiler decides at run time can that happen??, I thought compiler job is to compile
@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
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.
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.
@javidx9, You are a mentor to me.
thank you.
This is DYNAMIC polymorphism. You can use STATIC polymorphism to some extent, and it is way more preferable in the realm of game development.
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
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.
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 🤣
8:19 vecObjects[2] is a pointer to A, how can you vecObjects[2].DoSomething() ?
It's basically the same as
A->doSomething()
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?
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.
@@UberMun right, which is apparently a turing complete language in itself...
so making an interpreter for PostScript would be more than an afternoon project
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.
Wait couldnt you just have a completely abstract class that is filled with virtual functions? Then if you make different subclasses you can put them all into one vector. Im not sure what you would do with that because none of them would be related, but could you?
Sure, that is polymorphism!
Every subclass has to define all functions marked as virtual. Or it'll be abstract itself.
What's the name of the track from the video called "How a glock works"
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.
@saladnuts start with assembly programming 👹
How to self study computer science plwase recommend me books list plus please sort them I want to learn it from beginning to end
How are you doing that with a Chromebook?
Remote desktop or he installed Windows on it.
Same question... Can you install windows on an Acer Chromebook? It's pretty zippy to be vnc.
same question
Can anyone explain how the equations at 20:01 work?
Shouldn't at 8:20 be Objects[2]->DoSomething() instead of dot as it's a pointer?
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).
@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
Do it however you wish...
@@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 ?
Does your salary justify your work (traveling all the time, etc)?
The job is interesting and reasonably unique.
luckily ive used java in the past, so I already understand this :)
At 38:16 i was getting scared, i thought what happened here xD
Nice explanation. I was wondering, is it possible to extend the idea of polymorphism to a higher order so you can have normal polymorphism between heterogeneous code (the parent class has been written in a different language and the child class is written in C++). I just observe that you need to have homogenous code (same language for the parent and child classes to have polymorphism of any type). This homogenous code idea is in every OOP language. Also i think that if you have a core language (ex. C++) and another language (obscure language like an esoteric programming language) then you can make the code more secure by an advance encrypted polymorphic scheme. I am thinking that in a large SCADA application you can exploit polymorphism in a nasty way to infect the code with a relatively small clever virus.
Greate Video
Do we not need to delete the nodes created using "new"?
I believe so.