madman uploaded in 2011 and still saves lives to this day... mvp
@saumyasingh76703 жыл бұрын
So true💯💯
@pawanchouhan15614 ай бұрын
Simple and to the point explanation.
@secretmaster54 жыл бұрын
Entertaining, informative, quick to the point and easy to understand. Everything my teachers aren't. Even 10 years later, low sound and all, these videos are better than a full university course. Thanks Bucky, you are a saint.
@SolANDSixela5 жыл бұрын
This is the mark where I have everything for my class. I would like to thank you Bucky for making these videos. You have been the most clear programmer and teacher for me. Have a blessed day!
@matiasssssssss4 жыл бұрын
you should check out jacob sorber
@lovelyshimly82613 жыл бұрын
@@matiasssssssss what does jacob sorber do? I checked his page and there is nothing about c++..
@matiasssssssss3 жыл бұрын
@@lovelyshimly8261 he does have plenty of c/c++ related videos. There are also vids where he explains something in general then shows some java/c/cpp code. He explains stuff so well in my opionion. Try searching a specific topic with his name afterwards like “linked lists jacob sorber”
@FatemaAbbasMoaiyadi Жыл бұрын
I have been trying to understand what my college professor is teaching us in C++ for soo long. I understood this way better in just 10 minutes. Thank you.
@ste4lthles2 жыл бұрын
Tutorial from 11y ago, has better quality, audio and content than most recent ones. Thanks for this.
@anfernny62783 жыл бұрын
This the best god damn tutorial. I was trying to understand this for 2 hours before reaching this video
@j33REN7 жыл бұрын
Bucky you are awesome.
@ryugagod7140Ай бұрын
He really explained a lot better than my prof. So much more clearly while showing an application. Helped out a lot, thanks.
@leeonzo45352 жыл бұрын
The first 2 lines in main are creating objects. Second 2 are connecting their addresses to some pointers Last 2 are running the function in each class (In main
@udk-tutorialsbyluke843411 жыл бұрын
Wow you are programming but stood at ground at same time to make us understand C++! Thanks and got my sub of course:)
@NatashasTemuFinds7 жыл бұрын
360p and still readable :/
@TrojanLube694 жыл бұрын
he is from the future.
@unknownguy20924 жыл бұрын
@@TrojanLube69 hey do u remember me bro?
@jose.a.a.a4 жыл бұрын
@@unknownguy2092 No.
@jjsdsounds Жыл бұрын
"whoa backslashes" - Bucky love this dude
@joaquintorres8343 жыл бұрын
You are a legend, Bucky! Take care and stay safe. Love from Spain.
@tek8711 жыл бұрын
The main difference is where it lives in memory. The "non pointer version" lives on the stack, meaning it will be invalid once the function returns, while the "pointer version" lives on the heap, which means it will be alive and well until somebody calls delete on it. In general it is considered best practice to put objects on the stack whenever possible, and only on the heap when needed.
@BurninVinyl7 ай бұрын
13 years later Bucky still the best teacher. To make it short: In C++, when using polymorphism, you can't directly use functions from derived classes in the base class, unless the base class has a virtual function, because the base class doesn't know about the derived classes' functions.
@mhazani8 жыл бұрын
SO simple! I've been trying to grok this for a while and your 9 minutes and 18 seconds just drove it home. Thank you, Bucky!
@Jaredvotesforpedro2 жыл бұрын
My man just explained this better in under 10 minutes than my prof did in over 2 hours.
@averyali9510 жыл бұрын
You made this topic and polymorphism so much easier than what my professor taught me, i thank you and keep it up. You were very clear and helpful
@abrarmahi4 жыл бұрын
2020 and this man is still saving my grades
@kevinallison757 жыл бұрын
Bucky's videos are a great way to clarify certain concepts. I really am grateful i found this channel
@dzuzr6 жыл бұрын
This is so legit. Really simple to understand. For anyone new coming here you can also declare it like this to get initialize and assign the pointer in one liners: Enemy *pNinja = new Ninja; Enemy *pMonster = new Monster;
@leavedrakealone18015 жыл бұрын
But I think then you will have to delete the pointer as well.
@rjgonzalez81083 жыл бұрын
@@leavedrakealone1801 True! The new keyword allocates memory from the heap so it needs to be deallocated using the delete keyword.
@WSEize11 жыл бұрын
"mponster attack"
@TrojanLube694 жыл бұрын
he does it on purpose, always. He is very clever.
@sathvikreddy57994 жыл бұрын
@@TrojanLube69 I don't think so , 'cause p is next to o in the keyboard, a typo error
@frankalfaro61244 жыл бұрын
Now that's a good 2020 way of thinking since there's literally a game coded for an imposter to attack that's very popular this year.
@stefano88807 жыл бұрын
holy crap. It took only 10 minutes for you to make us understand virtual and it is better than my professor explaining it.
@djdancealone34197 жыл бұрын
Bucky, You explain concepts so well. Truly appreciate your work.
@michal2344868 жыл бұрын
I think he could have accessed the setAttackPower from the level of both derived classes, so n.setAttackPower(14) because setAttackPower is public. Is that correct?
@thegamingruler199612 жыл бұрын
im soo excited coming to the end of the series and starting the GUI tutorials shivers down my body
@SirRobbStarkGamin10 жыл бұрын
So in short, we use virtual to tell the parent class before it start outputting to check the child class for similar function with same parameter, and if it finds it, it would output the function in child and if it cannot it'd out put the function in parent.
@syedwasay30876 жыл бұрын
exactly but needs to done through pointers :D
@RivenbladeS8 жыл бұрын
"woohh easy backslashes" hahhaha
@karmaindustrie5 жыл бұрын
back off backslashes!
@tuanvu51615 жыл бұрын
lol just thought that I'm the only one laughing at that sentence :)
@notzuhriashraaf49124 жыл бұрын
I laughed at it too!
@heavestern11 жыл бұрын
this is i love youtube there is always someone can explain a thing best way you can understand ty man was much easier this way
@menglixia64705 жыл бұрын
hmmm.. enemy1.attack() should probably be anemy1->attack() around 1:10, as enemy1 is a pointer?
@Vorbis513 жыл бұрын
It blows my mind how bucky can teach weird concepts like noone else.
@DjCastoo10 жыл бұрын
It's good to have examples, my programming teacher gives us theory without any examples wich makes it very hard to understand we you need to put it to practice ! Thank you so much, very clear and simple !
@kousoulides11 жыл бұрын
yes it works both ways in this example, but this is just to show you what is polymorphism in the most basic way possible, imagine if you had a virtual function than did something: virtual void f(int n) { std::cout
@AnderzSwe9413 жыл бұрын
@thomastancksVideos the -> operator is used for pointers to reach the members of the object it is pointing at
@samidessuky51513 жыл бұрын
2021 and still saving lives. You a real one Bucky :')
@Alfredo58833 жыл бұрын
Yeah true. Best explanation of Polymorphism on YT
@thespacedan.2 жыл бұрын
its a great world where i can find a better teacher and learning resource for free on youtube rather than a university that I pay a hefty amount to
@BelievinSP8 жыл бұрын
thanks! I love this "explain it to me like I'm 5", video. It's short and sweet
@scottpowell520510 жыл бұрын
Ciuculete Cosmin - if you have just one or two objects like "m" and "n" - there would be no reason to. But what if you have 1000 objects stored in an array - and they are all different types. If I wanted to loop over all 1000 objects and have each of them attack, lot simpler to put all the different types of monsters into a single array of enemies. Or maybe I have an indeterminate number of objects - like theres a randomness where every 5 to 10 seconds a new enemy is spawned (using "new" to create a new object). If I have a dynamic number of objects, you need polymorphism to be able to call shared methods on all of them.
@Kytuzian13 жыл бұрын
Whenever you say you're going to shut up, you never do. I liked it anyway.
@BirdPEE11 жыл бұрын
Thank you for your clear and entertaining explanations Bucky! I was so confused in class.
@bsgamer50694 жыл бұрын
It’s 2021. But your explanation rocks
@gregkan39647 жыл бұрын
polymorpihsm comcept is quite easy to understand and the example used is very good, what confuses me is, do we really have to use pointers to have access to attack function ??
@roma.senatosu4 жыл бұрын
I really like your tutorials. You are explaining very well and of course you make us smile 😊
@shubhankarpotdar545811 жыл бұрын
Dude...ur awsum!!! You have explained it in real simple language...its been extremely helpfull..thanks a lot!!!
@DimitrisHD8 жыл бұрын
Dude, i love you.
@majedalghanmi74297 жыл бұрын
thanks allot : you a best teacher for c++
@pepsico8158 жыл бұрын
Why doesn't he just do n.attack(); ?
@odbodbo8 жыл бұрын
I think it is just to show you that it can be called from the base class. Imagine that you'd have a list/array of enemies but you don't know if each element is a Ninja or a Monster. Then you can still just say something like: enemies[i]->attack();
@gamedevnow75518 жыл бұрын
Yes, I a agree with odbodbo, Imagine you have 30 types of pokemons, and each type have an "attack" method which differs a little bit from the other type, say pokemon from water splashes water, from fire spits fire and so on. So, instead of saying, Poken of fire attack fire, pokemon of water attack with water.... you just say, POKEMONS ATTACK, and each type will perform the attack according to its specialization. It is useful when we have different types but under a collection which derived from a common base class, and we can treat them as "equal" due to the fact that they come from the same ancestor but each will perform a different attack.
@dzmitryk96587 жыл бұрын
I'm so happy I've looked at this thread :D Thank you guys!
@mazhartejani7 жыл бұрын
Thank you so much for the brief explaination, it helped me alot, to understand this concept.
@bouzie80007 жыл бұрын
perfect. I was confused as well
@ParthPatel-yj6fc8 жыл бұрын
Why is it possible to assign an Enemy class object pointer to the address of a 'Ninja' class object 'Enemy *enemy1 = &n'?. The Ninja class may contain more information than the 'attack' method; in that case would it still be possible to use 'Enemy *enemy1 = &n'?
@MrGamenewb12 жыл бұрын
You are an awesome teacher! But i got one question. When the destructor of the classes Monster and Ninja are called and then there would be also a need to call the destructor for the class Enemy, wouldn't it? However i am not quite sure about this, but i think you need to make a virtual Destructor so that the class get destroyed properly, otherwise you get a Memory Leak, or do i mix up things, can you help me?
@fuondjingamietee48845 жыл бұрын
ahaha "public enemy" like this if you peeped too
@skolanbrinner12 жыл бұрын
Indeed, KZbin really needs better c++ Windows API tutorials
@realm08713 жыл бұрын
@Cezarijus if you wanted to create an array of pointers, let's say, a list of different enemies with monsters, ninjas and such things you would need a virtual function from the base class enemy to be able to call the attack function from the enemy elements in that list. If you just had the attack functions in the derived classes your program woudn't be able to call it from a pointer to a base class. That's the greatest value of virtual functions.
@paulmouton67656 жыл бұрын
I am currently studying Computer Science at a South African university where the lecturors can't explain anything in class. The whole subject is basically self-study for us. Your video's just saved me from failing this subject. Thanks SO much
@1mol8312 жыл бұрын
That’s harsh. Feels bad for solitary though
@ciuculetecosmin438010 жыл бұрын
ok...but why wouldn't you just n.attack(); and m.attack(); and call the functions respective to the ninja/monster itself instead of calling them from an enemy that points to a ninja/monster?
@nerickamkech27304 жыл бұрын
Because it is useful for other purposes For example these are Enemies Ninja - has attack function Monster - has attack function Then we will add Slime let's say it doesn't attack Slime - No function Okay now For example you want to set rules - If you fight a non hostile enemy like slime, you want the user win in first turn so our function is I'm going to make a variable that checks if that class has it function bool friendly; If 1 = has no attack function If 0= has an attack function Void checkenemy(Enemy *pEnemy){ if(*pEnemy.friendly == 0) //Execute the attack which the slime has no attack function *pEnemy.attack(); Else //win the User } We can use that in method functions or statements that execute the specific function that owns by the class that have it only This is the example I taught why we need to use that
@robertneville77711 жыл бұрын
Great explanation on virtual functions! Thanks!
@seigeengine12 жыл бұрын
Welcome to tutorials that expect you have a clue what you're doing. You'll get there some day, champ!
@masudzaman88414 жыл бұрын
Why instantiate an Enemy object when I can use the dot operator to set the attack power? such as n.setAttackPower(29)
@cmopix13 жыл бұрын
@irtifakhan17 you can do this in this specific example, but what if you don't know whether you have a ninja or a monster or another type of monster. Let's say you enter a room and some randomly generated different types of monsters appear, through polymorphism all those specific monsters know how they're supposed to attack.
@Impulse_Photography5 жыл бұрын
Does this (virtual functions) work with ' Composition' also or is it just for ' Inheritance? '
@Invisibleman398 жыл бұрын
...thanks allot for good tutorials....i have a question...why you have not created constructor inside classes....isnt it necessary to have constructor??!
@bartoszantczak16138 жыл бұрын
Every class has a default constructor, which means it isn't necessary to write one. Writing a constructor overloads the default constructor and allows you to customize how your class is instantiated (compared to the default values set from the default constructor).
@Invisibleman398 жыл бұрын
Thanks.....
@janisl.698210 жыл бұрын
Mponster - monster what likes listening MP3 and attacks you with bad qualitaty music :D
@shamanik13206 жыл бұрын
So adding override is just for clarity but doesnt do anything itself, right?
@nasriwidaatalla67114 жыл бұрын
Great way of delivering information..
@harilalmn8 жыл бұрын
Bucky, I tried it by calling the setAttackPower method directly from Ninja n and Monster m and it worked well. Then why do we use the enemy1 and enemy2 pointers to call the method? Kindly see the code below; Ninja n; Monster m; //Enemy *enemy1 = &n; //Enemy *enemy2 = &m; //enemy1->setAttackPower(25); //enemy2->setAttackPower(100); n.setAttackPower(25); m.setAttackPower(100); n.attack(); m.attack();
@harilalmn8 жыл бұрын
Thankyou...!!!
@shubh_chaudhri5 жыл бұрын
tutorial for generations to come...
@PalaRossonero3 жыл бұрын
Man , you're so good at explaining!, Thank you so much!
@kostastsigkounis878411 жыл бұрын
Very helpful! Thanks thenewboston!
@kylebb19016 ай бұрын
This is explained so so so well!
@aka09896 жыл бұрын
tthen why shouldn't we just use the attack method of the object m or n that we created it directly ? still cant get the point of virtual func ...
@scotfsh50142 жыл бұрын
love this tutorial so much, thanks Bucky.
@omidheidari67116 жыл бұрын
this guy is a good teacher and he is so funny, easy backslashes :)))
@jkracing8 жыл бұрын
hey bucky have you created any apps or games that are in the app store?
@NikorasuChan12 жыл бұрын
Halfway through the tutorial series, its tea time break! XD (and its still morning...)
@krupt59956 жыл бұрын
yes but in separate class files the other classes are unaware of the Enemy one so how is this possible?
@moreorless65238 жыл бұрын
just a correction to the video: C++ doesn't have virtual variables.
@Mark13129210 жыл бұрын
You're absolutely amazing. Cheers from Portugal ;)
@midas25706 жыл бұрын
so last video you talked and showed us polymorphism, but in this video you say "In order to have ploymorphism, you need this virtual stuff." but there was no virtual stuff which you talked about polymorphism. So which one is polymorphism?
@karmaindustrie5 жыл бұрын
5:02 what is that word "mice" ? ... "i mice'le just code.. " / "i mussle just code... " i hear that a lot from another guy (AJ Miller) but i never figuret out how to look it up because i can not write it. ... missal? ...moical? The context always sounds like "i RATHER do xy"
@P4rkerMann5 жыл бұрын
"I might as well just code it" he just said it fast.
@karmaindustrie5 жыл бұрын
@@P4rkerMann Oh my goodness, thank you so much I was lookin for that mystery for ages!
@P4rkerMann5 жыл бұрын
Karmaindustrie you’re welcome! :)
@DJayDiamond4 жыл бұрын
If you are going to have different function definitions for each type of enemy then why use polymorphism at all? Just to avoid having to type the different names? I'm guessing it's just a convenience thing. Like for basic programs you can probably get away without using polymorphism at all right?
@sihonglu568712 жыл бұрын
umm i would like to ask what if use Enemy enemy1=n; and Enemy enemy2=m; I tried that and got some random gibberish in return.... is it because by doing so, you are making a copy of the object n and m, and assigning it to the enemy objects and by printing out the n.attack(), and m.attack() the value of attack power is not changed in them?
@JoeDaHond12 жыл бұрын
Why whenever I use inheritance of classes it shows up as an error? It says: error: new types cannot be defined in a return type note: (perhaps a semicolon is missing after the definition of 'Monster') error: two or more data types in declaration of 'main'
@shmuelbachar32257 жыл бұрын
i have aquestion! if i want to add to virtual setattackpower number and than to show the number when i call void attack how did i do that ?
@imcool134713 жыл бұрын
i honestly love you bucky
@davidwesh4123 Жыл бұрын
Great an straight to the point.
@seekergaming28174 жыл бұрын
i dont understand the difference between tutorial 55 en 56... only difference i see is that buckey didnt give a value to attack which spared him 2 lines but the rest was pretty much the same... can someone explain pls :/
@agnesakne44097 жыл бұрын
I remember getting compiler error after using the virtual specifier in the method definition in .cpp file, this specifier is only to be used in the declaration right?
@daxola19 жыл бұрын
Why don't they teach us this a lot more heavily in CS? This is very useful. Thank you.
@holybubbles11 жыл бұрын
What exactly is the difference between what you did in this tutorial and the previous one?
@martinsvk1711 жыл бұрын
For example you can have 1000 different types of enemies and you can still invoke attack from all of theme just by using a for each loop like for example in java u make for Enemy e : enemyList { e.attack() };
@3zombie81 Жыл бұрын
I forgot what virtual does, now I get it.
@iqrapervaiz89557 жыл бұрын
Derived class can only initialize members of base class using overloaded constructors Derived class can not initialize the public data member of base class using member initialization list can you please explain this concept.
@hopa-ys2bc8 жыл бұрын
I think u can just use setAttackPower to derived objects n and m without switching twice with m.enemy::setAttackPower()... Polymorphism is not needed in that example i guess
@lijasssss13 жыл бұрын
a value of type "type" cannot be used to initialize an entity of type "type" if i get this error, what do i do ?
@janicejackson6057 жыл бұрын
Hi, love ur vids, I have a question tho... What the heck does line: Enemy *enemy1 = &n; acctually do??? I can't wrap my head around that...
@janicejackson6057 жыл бұрын
Thanks for your answer! But isn't enemy1 an Enemy object already?
@92steamer11 жыл бұрын
Why you are not my University professor ? ;( Thanks a lot,everything is much easier than I thought.
@RudeGuyGames10 жыл бұрын
***** I think he died.
@jozestrozer7 жыл бұрын
Nope
@mysticlunala80204 жыл бұрын
@@jozestrozer Still no. He just posted something on Reddit a month back. :))))))))
@cixin10x3 жыл бұрын
Captain America saved Bucky for a reason.
@asimshah18242 жыл бұрын
True dat😂
@usmanshahid48919 жыл бұрын
Okay so I've got a question. The guy here first declares a Ninja object: n and a monster object: m. He then declares two enemy pointer objects (enemy1 and enemy2) and assigns them each to n and m. Wouldn't it have made more sense to declare a ninja object: enemy1 and a monster object: enemy2 and used their respective attack functions thereby removing any use of the virtual functions. Don't get me wrong. I understand there are numerous ways to tackle a problem. But the thing is that I'm trying to think of scenarios where virtual functions are actually useful and I'm drawing a blank. :/
@juice122229 жыл бұрын
Usman Shahid I get what your saying, this is just an example as how virtual functions would work with pointers if needed to. 3 Reasons why you would use virtual functions/late binding. (1) when a program has a variable declared as a pointer to a base class object but which sometimes points to a derived class object.(this example).(2) When a variable is declared as a reference to a base class object but sometimes is a reference to a derived class object.(3)When a base class function calls a function that is defined in both the base class and derived class. I think you need an example of number 3 to really give you another example of why virtual functions would help.
@Rin-qj7zt9 жыл бұрын
+Usman Shahid try storing your ninja object and your monster object in the same array. it can't be done. to fix that, create an enemy array and use the method in the video. now you can store your ninja object and your monster object in the same array. Ninja n; Monster m; n.attack(); m.attack(); Ninja narray[2]= {n,m}; // this is invalid Monster marray[2]= {n,m};// this is invalid Enemy Earray1[2]={n,m}; // even this is invalid Enemy *enemy1 = &n; Enemy *enemy2=&m; Enemy *Earray2[2] = {enemy1,enemy2}; // this is valid. now we have an array that holds 2 different class objects. (well technically it holds the pointers to those class objects, but i digress) using the virtual function scenario taught in this video, the statement Earray2[1]->attack(); becomes valid. (though the syntax for that last one might be off because i've never used this method before. for example, i have no idea what the syntax is for storing pointers inside an array.)
@ramyapriya72579 жыл бұрын
Guys,Help me understand something. If it is called run time polymorphism,shouldn't the error be shown during run time?
@broochii7 жыл бұрын
amazing work bucky. thanks.
@colinhicks66077 жыл бұрын
my biggest complaint with the last two videos was that even though he explained the how very well, he didn't really explain the why. Why use pointers to the monster and ninja objects (turns out efficiency). It makes sense now, but he never explicitly said it in the video he just showed us why its valid.