Buckys C++ Programming Tutorials - 55 - Introduction to Polymorphism

  Рет қаралды 433,605

thenewboston

thenewboston

Күн бұрын

Пікірлер: 353
@joshuapierson801
@joshuapierson801 11 жыл бұрын
I will say this. This guy is awesome I have a little more programming experience than he does but, the way he is explaining things is not only clear BUT RIGHT. I will always see videos, even from college professors, that explain things that are all WRONG. This guy deserves credit and his videos are a great reference or a resource if i need a refresher. Thanks Bucky Keep At It.,
@TheK00paKingdom
@TheK00paKingdom 9 жыл бұрын
*Let me clear this up:* Here is a basic form of Bucky's code Ninja n; //Creates a ninja enemy n.setAttackPower(29) //Sets damage n.attack // Applies damage That code *would* work, but, when you are programming, you want your code to be fast, and efficient. Pointers are faster, because of how they are used in the computer. Ninja n; //Creates a ninja enemy Ninja *np = &n //Creates pointer to ninja enemy np->setAttackPower(29) //Sets damage np->attack // Applies damage That's all well and good, but why do we have to get the enemy class involved? Ninja n; //Creates a ninja enemy Enemy *e = &n //Pointer stuff e->setAttackPower(29) //Sets damage n.attack // Applies damage Well, as crazy as it sounds, it's easier to deal with, because of virtual functions. I promise you, watching the next video will clear up some of your concerns.
@parikrama88
@parikrama88 9 жыл бұрын
+TheKoopaKingdom Awesome explanation buddy!! Gr8 help :)
@sweeseen9577
@sweeseen9577 8 жыл бұрын
commended
@sethiojas
@sethiojas 8 жыл бұрын
+TheKoopaKingdom Dude I had the same thing in mind. Why use enemy class. Cheers!
@ReddoX30
@ReddoX30 5 жыл бұрын
Thank you for the explanation, it cleared things up a little!
@lilweez2175
@lilweez2175 4 жыл бұрын
Nigga, nobody understands pointers bitch
@puffbluesam021
@puffbluesam021 10 жыл бұрын
Sadly, my professors didn't teach us these techniques or concepts. Thank you so much Sir Bucky! You deserve a tuna coming from Tina! :)
@1mol831
@1mol831 2 жыл бұрын
Python feels easier but then this runs faster. Also struct in C is more straightforward. But I could see the appeal of class. (Though why can’t I just write a library of functions instead?)
@Thriving_in_Exile
@Thriving_in_Exile 11 жыл бұрын
This one in particular was EXTREMELY useful. Thanks, boss. Aaaaaaaaaand let's just go ahead and end line.
@alexisperez4581
@alexisperez4581 10 жыл бұрын
Wow I learned polymorphism in 10 minutes. Thank you sir
@phe2003
@phe2003 12 жыл бұрын
@allaboutmath, not necessarily true. The special case is that both the Base and Derived classes have the same function which is declared "virtual" in Base. Then we can use a Base pointer to point to either a Base object or Derived object. Which version of the function will be called depends on the "dynamic" object which can only be detected at "runtime".
@JrJreet
@JrJreet 13 жыл бұрын
this is probably the most usefull c++ tutorial to me in this playlist until now lol
@kashmutt
@kashmutt 13 жыл бұрын
After this video, I went back and took a good look at pointers. I don't think I could have understood it without watching your tutorials. Thanks a lot!! :D
@hamsalak9779
@hamsalak9779 3 жыл бұрын
10 years ago and yet such a high quality. Tnx
@moonquartzs
@moonquartzs 3 жыл бұрын
If Bucky didn't exist, I'd fail my labs and exams. THANK YOU BUCKY!
@nasriwidaatalla6711
@nasriwidaatalla6711 4 жыл бұрын
Bucky is a great programming instructor. You can use enemy1 and enemy2 if they were Ninga and monster type respectively. Also you can access the function by pointer (if it was a Ninga type for example) by typing enemy1->attack();
@Javii96
@Javii96 6 жыл бұрын
This was a perfect illustration of polymorphism for me to understand. Thanks!
@fidahussain6366
@fidahussain6366 4 жыл бұрын
Sir Bucky, these are nodoubt The Best! c++ tutorials. Love you 💕
@DFsdf3443d
@DFsdf3443d 9 жыл бұрын
Im a ninja and Im offended.
@eeeflying8632
@eeeflying8632 7 жыл бұрын
Thats because ninjas are pussies
@mr.marmot39
@mr.marmot39 7 жыл бұрын
because you're "public" enemy
@bredmond812
@bredmond812 6 жыл бұрын
Yeah! I am a monster, and I feel the same way.
@b78418364
@b78418364 6 жыл бұрын
you are a public enemy number 2
@danaadalaide5648
@danaadalaide5648 6 жыл бұрын
There is always one.
@ImaginaryHuman072889
@ImaginaryHuman072889 7 жыл бұрын
"eating you doesn't kill you, it only does 25 damage"
@BrandonGamingTV
@BrandonGamingTV 10 жыл бұрын
I still don't get the point. Instead of making pointers, why don't you just write: n.setAttackPower(29); m.setAttackPower(99); and then call n.attack() and m.attack() in the main. What is the point of the pointers?
@krgrief
@krgrief 10 жыл бұрын
in this example, just to familiarize viewers with them. eventually, when you're passing class objects to functions, you don't want to pass the entire object by *value* (because it's usually larger than a pointer), so you use pointers. it's faster, albeit more confusing.
@yangzhang3686
@yangzhang3686 10 жыл бұрын
krgrief hello I also have this question. As you said, using polymorphism transfers a pointer to functions instead of the entire object, but couldn't we transfer the reference to the functions? e.g. in the nijia example, I don't use polymorphism, but transfer &n to functions? thank you! I really want to know where polymorphism is good.
@krgrief
@krgrief 10 жыл бұрын
Polymorphism isn't passing an object to a function using a pointer. That's "pass by pointer". Polymorphism is using a member function of the parent class to access private members in a derived class, if that makes sense.
@yangzhang3686
@yangzhang3686 10 жыл бұрын
krgrief Yes that makes sense! But what if child class has its own extra members such as: class monster: public enemy { public: int extraMember; }; I tried to access extraMember (which is not in parent class enemy), but it failed. does that mean if i want to access child class's members(which mother class doesn't have), I will not be able to use polymorphism? Or in other words, is polymorphism only limited to the situation that child class doesn't have its own members other than the ones inherited from parent class? Thank you so much!
@krgrief
@krgrief 10 жыл бұрын
Yang Zhang How did you try accessing extraMember?
@skippyscourge181
@skippyscourge181 12 жыл бұрын
I have a question.... i've tested this, and i've found that n.setAttackPower(29); n.setAttackPower(99); works just fine, and replaces the 4 lines of code of our two enemy objects. I understand that we're learning about polymorphism, but what are the advantages of doing it this way, when it seems like c++ already handles it automatically?
@maxim25o2
@maxim25o2 4 жыл бұрын
I thing there is an answer why He use pointers.. kzbin.info/www/bejne/pJXdZHh-pat4kMU
@sam-u-el
@sam-u-el 4 жыл бұрын
@@maxim25o2 memory management
@codeforkrishna
@codeforkrishna 3 жыл бұрын
pointers are faster and lead to better memory management, if you wanna reduce the number of lines, then use the "new" keyword to assign a new memory address to the pointer of the base class(which points at an object of the child class) in the following manner: mother *obj1 = new daughter; //"daughter" class inherits from "mother" class
@illyakoshkin3771
@illyakoshkin3771 9 жыл бұрын
probably repetitive question, but why you need to create an Enemy obj, since this is a base class and Ninja will get everything from Enemy anyways? why not just say: Monster m; m.setAttackPower(90); m.attack(); instead of: Monster m; Enemy *e = &m; e->setAttackPower(90); m.attack(); or if you want to use pointers so badly, why not Monster m; Monster *mp = &m; mp->setAttackPower(90); mp->attack(); why would you choose to confuse us? ;)
@acqbilal16
@acqbilal16 5 жыл бұрын
This is exactly what I was thinking. What difference does this make?
@alexandrufilipescu1301
@alexandrufilipescu1301 5 жыл бұрын
A bit late but maybe it is because this way he can have multiple enemies with different attacks?
@naniwho4691
@naniwho4691 5 жыл бұрын
It is because for an example might want to strore it in an array[ ] of all kinds of enemies(ninjas, monsters, etc..) And because vector is a great dynamic array, and it is very easy to use and learn, i will give you and example with how you can use it in vector array.... So basically this will happen: vector EnemyArray; for(int i = 0; i < EnemyArray.size(); i++) { // In that 'for loop', you can access all of your Monsters and Ninjas, thru the Enemy pointer. // You can make an 'if statement', that says for example: if (attackpower > 60) // cout ShowNameOfEnemy() // There is no ShowNameOfEnemy function, but you could type one. Basically this is the main idea, // to be able to just access all your objects from a single array. }
@chosen_x_create7708
@chosen_x_create7708 4 жыл бұрын
exactly my point , the calling and passing by address was not necessary , should have just called it through the objects and function
@RoninXsumari
@RoninXsumari 10 жыл бұрын
Awesome definition of polymorphism!! Thankyou!!
@briancarducci6351
@briancarducci6351 8 жыл бұрын
Darn, I was dissapointed to see you didn't make a Public Enemy joke...
@JauVi85
@JauVi85 7 жыл бұрын
:D
@jcinaty89
@jcinaty89 4 жыл бұрын
Thank you sooooo much bro. These examples are exactly what i need! you da best
@andyc.5878
@andyc.5878 6 жыл бұрын
Im watching this video 7 years from when it was released
@SomeDSquares
@SomeDSquares 4 жыл бұрын
9 years now m8
@dsdcp
@dsdcp 3 жыл бұрын
@lazarpuppet almost 10 years now.
@pedrobenitez2191
@pedrobenitez2191 3 жыл бұрын
thanks bucky from c++ student at Johns Hopkins
@NikorasuChan
@NikorasuChan 12 жыл бұрын
Wait what? One day tutorial 1 -> tutorial 55? O.o LETS PARTAY! XD I'm not confused of all of the topics from 1-55 :D
@abhisheksamboddu6580
@abhisheksamboddu6580 4 жыл бұрын
cool dude i took 2 days ..haha
@Vertigo6000
@Vertigo6000 7 жыл бұрын
Mentions video games, immediately draws all of my attention. Lol
@AnonyMouse316
@AnonyMouse316 12 жыл бұрын
Don't quote me on this, but from what I have heard from a teacher of mine is that if possible, use as many pointers as possible. He said that it is much more efficient to pass by reference rather than to pass most values.
@2coolrun308
@2coolrun308 7 жыл бұрын
I don't mean to be a dick here, but this is WAAAAAAAY better than my professor who can't even speak English.
@letmecommentalready
@letmecommentalready 12 жыл бұрын
you use pointers because in larger programs, you will be able to use all of your objects functions in a loop instead of individual statements for each one. something like creating an array of pointers to print out all of your classes getFunctions. you declare the pointer array like baseClass * myArray[3] = {&one, &two, &three} then you just put it in a loop to print it all out
@kashmutt
@kashmutt 13 жыл бұрын
You have got some wild imagination bucky! I love your tutorials!!! :D
@emad-man5227
@emad-man5227 4 жыл бұрын
Yo you still alive?
@Inshaine
@Inshaine 10 жыл бұрын
I uh... just made four Ninja objects (bruceLee -- not a ninja, I know -- donatello, snakeEyes, greyFox), and four Monster objects (freddyKruger, jasonVoorhees, creeper, bettyWhite) and made a new function to give them names that prints out "I am (name), ninja chop!" and "(name) must eat you!"... Thank you, Bucky! This is awesome!
@jrM5492
@jrM5492 6 жыл бұрын
after made it through the 51 video, man it goes smooth
@curtislbyrd
@curtislbyrd 13 жыл бұрын
I really love the way you tell it man..no doubt!!
@sammaine6953
@sammaine6953 10 жыл бұрын
Cleared up everything in 10 minutes, instead of sitting through a whole lecture.
@Shegg77
@Shegg77 13 жыл бұрын
@Cezarijus He was showing you important details about polymorphism which allow you to make a base class Pointer which point to inherited.
@webnavigator000
@webnavigator000 11 жыл бұрын
thanks for explaining. How come you don't use New keyword? I really don't know when do we need to use New keyword to instantiate object.
@CrunchyFishy
@CrunchyFishy 12 жыл бұрын
actually, it does not matter where you put your braces it's personal preference. In PHP and Java I prefer to write: function(){ } were as in C++, I prefer to write in: void function() } } ONLY because of the extra stuff that may be added to the end before the opening brace.
@mastermax7777
@mastermax7777 13 жыл бұрын
great tutorial bucky !!! love it ...
@SCHUCH512
@SCHUCH512 13 жыл бұрын
Feeling some C++ Game Development videos.
@SirRobbStarkGamin
@SirRobbStarkGamin 10 жыл бұрын
So Bascally what Polymorphism is, when you have a parent class that has multipal child class, and the parent class will take different forms (poly = many, morpic = forms) accordingly to the child classes. Just like how enemy changed for the ninja and monster. This basically makes coding a lot less and cleaner. since we can use one parent class over and over again.
@mohhamedrafi4763
@mohhamedrafi4763 10 жыл бұрын
By they that thing buckys doing with the class for example public :
@mohhamedrafi4763
@mohhamedrafi4763 10 жыл бұрын
mohhamed rafi dam youtube back to what i was saying it like public : void attack(int a) {cout
@yangzhang3686
@yangzhang3686 10 жыл бұрын
so does that mean it make the codes cleaner? e.g. it is easy to tell that enemy1, enemy2, enemy3 are from the same base class, whereas it is harder to tell if nijia, monster are from the same base class? thank you.
@mohhamedrafi4763
@mohhamedrafi4763 10 жыл бұрын
Yeah it dose. If you are a program you should try to keep your program clean as possible so other people can have a easy time reading it.
@mohhamedrafi4763
@mohhamedrafi4763 10 жыл бұрын
Wow I need spell check. So if you did not get what i mean if you are a programmer you should try to keep your code clean
@martinsvk17
@martinsvk17 11 жыл бұрын
Yep, youre right... 1st time I see Buckys made a mistake a little bit. The origin of polymorhism would be clear when you do it like this : You make a function attack also in you Enemy class. Then you make Enemy e1 = &ninja and the same way for monster. And then you can call maybe in a for each loop for all enemy instance just e1.attack(), e2.attack() and all the attacks do their own stuff and they call the same, i think it also call method overriding (in java).
@essamgouda1609
@essamgouda1609 8 жыл бұрын
I get why its allowed to type Enemy *enemy1 = &n; but why do we even use it ? why did we thought about using pointers and addresses not equalizing them normally ( although I tried Enemy enemy1 = n;) and it didn't give me an error but didn't work also and I know you can't just equalize objects like that but I am confused by the idea of using pointers in here ?
@lechi_2002
@lechi_2002 8 жыл бұрын
This might help you: stackoverflow.com/questions/22146094/why-should-i-use-a-pointer-rather-than-the-object-itself
@essamgouda1609
@essamgouda1609 8 жыл бұрын
Thank you so much !!!!!
@talhaahmed3895
@talhaahmed3895 8 жыл бұрын
Now That Moster and Ninja Makes it more interesting! than boring variables and classes
@NikorasuChan
@NikorasuChan 12 жыл бұрын
I learnt most of it beforehand in another language... and its a quite easy transition... so its a no worry for me ;)
@user-og6ol2im7v
@user-og6ol2im7v 8 жыл бұрын
Couldn't the attack power be set inside the ninja and monster classes?
@user-og6ol2im7v
@user-og6ol2im7v 8 жыл бұрын
***** thank you very much
@bloggerswork899
@bloggerswork899 6 жыл бұрын
@Don't Touch Me Simp
@veljko100able
@veljko100able 5 жыл бұрын
what's difference between video and this: Ninja n; Monster m; m.setattackPower(29); n.setattackPower(10); n.attack(); m.attack();
@j.s.53
@j.s.53 4 жыл бұрын
Why is it printing garbage value for me?...
@J0nDaFr3aK
@J0nDaFr3aK 11 жыл бұрын
hey all, everything's clear to me but why the pointers? why not just access the setAttackPower() function from the objects itself? like, n.setAttackPower(x) and m.setAttackPower(y). wouldn't this work? the pointers here seem like no use to me here
@avi_mukesh
@avi_mukesh 8 жыл бұрын
If the class Ninja is the derived class of class Enemy, would it make any difference if you wrote: n.attackPower(29) Instead of creating a pointer and all that confusing crap? I mean, ninja has access to all functions that are inside of the enemy class, right? What am I missing here?
@avi_mukesh
@avi_mukesh 8 жыл бұрын
*setAttackPower
@Thelouqman
@Thelouqman 11 жыл бұрын
Thanks , its really helpful
@zablablukas
@zablablukas 8 жыл бұрын
Uhm so what's the point of polymorphism? Couldn't I just not make pointers and directly call n.attackPower(23); m.attackpower(56) and then n.attack(); m.attack() ? It would be more simple that way
@SW-hx4rl
@SW-hx4rl 8 жыл бұрын
zablablukas exactly what I'm wondering too... can anyone explain?? Why call the functions on pointers rather than objects themselves??
@MrSonikProd
@MrSonikProd 8 жыл бұрын
yeah was wondering too
@ceriwestcott8784
@ceriwestcott8784 8 жыл бұрын
lets say you have a Class Person and 2 sub classes Female/Male with the methods "printSex". You can make objects like Person p = new Male(); Person p1 = new Female(); Vector persons = new Vector(); for(int i =0; i < persons.size(); i++){ cout
@ahmeddeghady4510
@ahmeddeghady4510 5 жыл бұрын
Why there was pointers in the code? was it really needed?
@gauravskumar5673
@gauravskumar5673 4 жыл бұрын
Why use pointer? Is there any advantage of using pointer?
@donovantheprogrammer2989
@donovantheprogrammer2989 4 жыл бұрын
Why do a pointer to Enemy and not just a pointer to Ninja?
@asadmehmoodleo
@asadmehmoodleo 12 жыл бұрын
can you please tell me the compiler name ?
@J0nDaFr3aK
@J0nDaFr3aK 11 жыл бұрын
Yeah i didn't get why he used pointers. so it can basically be done without them, right? what's the use of pointers here?
@giancarlo426
@giancarlo426 2 жыл бұрын
"All ninjas are enemies ... we already know that." Lmao.
@muneebmuhammad1608
@muneebmuhammad1608 6 жыл бұрын
why cant we replace the pointers with normal declaration.
@seigeengine
@seigeengine 12 жыл бұрын
You use pointers to keep a reference to an object. Otherwise you're always passing by value. AKA: Making copies. Also memory tricks, etc. etc.
@ismailelshafey1003
@ismailelshafey1003 3 жыл бұрын
it's 2021. This ladies and gentlemen is how to make passive income
@abirhossen5308
@abirhossen5308 9 жыл бұрын
that ninja chop killed me xD
@mmykandil
@mmykandil 13 жыл бұрын
ok I understood the polymorphism idea from the Java tuts but now this video missed it up :(
@letmecommentalready
@letmecommentalready 12 жыл бұрын
"Also, I really don't know why he used pointers for this." Yea, sounds like I added a lot of stuff you already knew.
@khasha6166
@khasha6166 4 жыл бұрын
Buckys C++ Programming Tutorials 2011 >>>>>>>>> University Professors 2021 :)))))
@51AD3
@51AD3 12 жыл бұрын
Why didn't he set the attack power of Ninja's and Monsters within their derived classes? I expect that they would always have the same attack power, so why set them inside of main?
@jeffreydilley3380
@jeffreydilley3380 7 жыл бұрын
are we not worried about slicing because you're passing the address ? wouldn't having the parent class be set as the child class lose the uniqueness of the child ?
@seigeengine
@seigeengine 12 жыл бұрын
That is basically exactly what I said. Adding redundant information is not useful.
@basslahat387
@basslahat387 6 жыл бұрын
really helpful thankyou.
@j3froc63
@j3froc63 5 жыл бұрын
setAttackpower was never used??????? Only made in the base class. And why would you want to make the pointers to monster and ninja of type enemy? Hasn't the classes ninja and monster already inherited the member variables/functions from class enemy?????? How are you able to set the attackpower a certain value for each object without using the setAttackpower function in the first place??????????????????????????????????????????????
@Canbay12
@Canbay12 5 жыл бұрын
absolutely right, because he declared attackpower as protected, the child classes inherited the attribute of the parent class directly,which makes implementing a set function and displaying the usage of polymorphism on this example unnecessary ...
@j3froc63
@j3froc63 5 жыл бұрын
I still don't get polymorphism. Shit video. I don't know where else to find a good video that explains the concept properly with a good example. FFs
@KishoreG2396
@KishoreG2396 5 жыл бұрын
@@j3froc63 10 months late, but here we go: 1.) attackPower can be used within derived classes and the base class method by itself without having to use setAttackPower(). This is because attackPower is a protected variable and you can access it within the class heirarchy (i.e. within their methods) but not outside of it. 2.) the reason you would want to make a pointer of type Enemy rather than a pointer of monster or ninja is to be able to use that data for ALL classes that are enemies. For example, lets say you have a function like this outside of the class: void DoSomethingWithEnemy(Enemy* myEnemy); If Enemy* were instead Monster*, that means you cannot pass an object of type Enemy or of type Ninja. The same would be true if it were a Ninja*. Thus, having it as an Enemy* means you can pass all pointers that are Enemies. Since both Monster and Ninjas are Enemies, they can be passed to an Enemy*, but an Enemy is not a Ninja and a Ninja is not a Monster.
@danagamer
@danagamer 11 жыл бұрын
You don't really need to use pointers for this? to work, right
@cybrhckr
@cybrhckr 7 жыл бұрын
SoloLearn app in the playstore used the exact same example in their virtual functions course. Did you know that?
@vardaan_agarwal
@vardaan_agarwal 3 жыл бұрын
Still helping in 2022 ❤❤
@maileong5511
@maileong5511 5 жыл бұрын
good explaination!
@areola_ayatollah
@areola_ayatollah 12 жыл бұрын
Is there any reason not use pointers here and write out like so? : Ninja enemy_ninja; Monster enemy_monster; enemy_ninja.setAttackPower(80); enemy_monster.setAttackPower(30); enemy_ninja.attack(); enemy_monster.attack(); I am struggling to find a use case for pointers...
@giancarloandrebravoabanto7091
@giancarloandrebravoabanto7091 5 жыл бұрын
so you use the base class to manipulate its derived classes.
@shatley123
@shatley123 12 жыл бұрын
i'm just learning c++ but i think it's suppose to work as like a way of organizing for example we might have a Vehicle Class, then maybe we want to have a Car Class and a Truck Class. the Car Class and the Truck Class can have the same stuff from Vehicle Class but they also have there own features. eh but what do i know
@elaineschmidt5338
@elaineschmidt5338 11 жыл бұрын
Is there a performance difference in using pointers to set the attack power instead of just using n.setAttackPower(29)?
@SpomenkoJabucar
@SpomenkoJabucar 12 жыл бұрын
Top notch tutorials.
@dannytheman2217
@dannytheman2217 7 жыл бұрын
So what was polymorphism exactly? Was it use of a class within a class ? I followed along and havent gotten to the portion of the book about polymorphism, but seems simple enough
@zunpre
@zunpre 13 жыл бұрын
Why not do "n.setAttackPower(29); m.setAttackPower(99);"?
@tryingmybest206
@tryingmybest206 11 жыл бұрын
I really don't understand. Please help! I thought that if you go Enemy *enemy1 = &n; it would make the pointer point to the ninja object, basically making it the ninja object. But then what did the fact that it was an Enemy pointer change about it? Did it change anything? Basically I'm asking why he used this line, and could not have just used the n object, and what it changes when a pointer is a specific type of class.
@minhnguyen-te4eb
@minhnguyen-te4eb 9 жыл бұрын
what if i have constructor , how can i use pointer
@donovantheprogrammer2989
@donovantheprogrammer2989 5 жыл бұрын
Put on your thinking caps for this one: "Member Enemy::attackPower is inaccessible". attackPower is protected
@SAURAV1403406SAXENA
@SAURAV1403406SAXENA 6 жыл бұрын
Can we typecast the Objects into parent class Public??
@skyworm8006
@skyworm8006 11 жыл бұрын
Do you think using a loop is a good practice for making something such as a text-based game that is turn-based?
@skyworm8006
@skyworm8006 11 жыл бұрын
Yes, I don't even know why I wrote this. 'Tis sort of obvious isn't it?
@volikoto
@volikoto 8 жыл бұрын
Does this mean that the enemy1 and enemy2 are the objects of the base class Enemy, and it pointed to the address of objects n and m? In that case the n object inherits the enemy1 as its base and then applies its changes?
@CrunchyFishy
@CrunchyFishy 12 жыл бұрын
So can someone explain why I would want to do this instead of just creating a variable int attackPower inside my Ninja and Monster class. I understand the need for inheritance for the functions but why not just make it simple and skip the pointer use
@ArslanGhaffar
@ArslanGhaffar 9 жыл бұрын
for this tutorial y access modifier isn't used ?
@DebaucherousDaniels
@DebaucherousDaniels 12 жыл бұрын
As always a life saver -
@youngslyyme
@youngslyyme 11 жыл бұрын
@7:07 what does -> mean in c++? Is there another alternative for using -> in your code?
@AhmedKhashabaa
@AhmedKhashabaa 11 жыл бұрын
you can use (*x).y=0; instead of using x->y=0;
@ujjwalmainali3927
@ujjwalmainali3927 11 жыл бұрын
Ahmed Khashaba (*x).y=0 in this case you are dereferencing a memory address and is equivalent to y=0 however x->y=0 is not deferencing but actually place 0 in the memory address of y.
@engelfriedrich9781
@engelfriedrich9781 10 жыл бұрын
why can't it work in visual c++? is coding C++ in Visual Studio different in the one that you use? thank you..
@BrandonGamingTV
@BrandonGamingTV 10 жыл бұрын
Is your code correct? C++ is C++. The program you use shouldn't be very wrong. I notice that his program automatically says return 0 at the end even if he doesn't write it, but the logic should still be the same.
@RedstoneEditor
@RedstoneEditor 11 жыл бұрын
I would assume it is similar to casting in Java?
@akshaykhobragade4871
@akshaykhobragade4871 9 жыл бұрын
It's showing an error that ‘ememy1’ was not declared in this scope. plz help
@utkarshjha657
@utkarshjha657 5 жыл бұрын
Can we inherit private values of base class by writing private instead of public, in derived class?
@WarnerBrosWannaB
@WarnerBrosWannaB 9 жыл бұрын
lol watching this at 2015 and time files!
@1kalekip1
@1kalekip1 7 жыл бұрын
Which files?
@akshayaggarwal5925
@akshayaggarwal5925 7 жыл бұрын
Flying files
@SomebodyOutTh3re
@SomebodyOutTh3re 6 жыл бұрын
to avoid working with pointers we can just use Virtual methods am I right ?
@Qazqi
@Qazqi 12 жыл бұрын
Congratulations. You've stumbled upon object slicing. You need a pointer or reference in order for this to work.
@brandonkejick4130
@brandonkejick4130 7 жыл бұрын
Heyy!! You used these examples from the SoloLearn app!!
@32Praful
@32Praful 6 жыл бұрын
Brandon Kejick it's the opposite
@izephyrmor
@izephyrmor 13 жыл бұрын
Thanks, Bucky.
@wssz112
@wssz112 9 жыл бұрын
what is the difference between this polymorphism and just override every attack(); in inherited classes
@XodinBlood
@XodinBlood 8 жыл бұрын
+Zheng SUn Thats whats I'm wondering, in the next video he shows the virtual function says it allows the function to know which class function to use, but it does the exact same thing here so, making virtual functions not that useful.
@vaypnishon1810
@vaypnishon1810 8 жыл бұрын
shouldnt the data member be private and can still be accesed through inheritance if you use a get function in the cout derived classes? so instead of protected and then trying to do cout
Buckys C++ Programming Tutorials - 56 - virtual Functions
9:19
thenewboston
Рет қаралды 378 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 940 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 576 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 679 М.
Practical Polymorphism C++
41:44
javidx9
Рет қаралды 126 М.
Dynamic Binding (Polymorphism) With The Virtual Keyword | C++ Tutorial
9:57
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 341 М.
Buckys C++ Programming Tutorials - 60 - class Templates
9:58
thenewboston
Рет қаралды 385 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 630 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН