C++ Tutorial 20: Inheritance Basics

  Рет қаралды 7,822

Creel

Creel

Күн бұрын

Пікірлер: 18
@_wouter52
@_wouter52 3 жыл бұрын
For people following the playlist, video 21 and 22 are missing. Here are links to those video's :-) 21: kzbin.info/www/bejne/qnjJk5-MbsxoobM 22: kzbin.info/www/bejne/h3iYpGdofsRqa8U Have fun!
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
16:58 lol gotta love our dogs letting people know this is THEIR turf and that person picked the wrong street to walk down. Dogs are so gangsta lol.
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
Btw video 21 and 22 are missing from your playlist for c++ but you probably knew that already. I'm guessing it's the polymorphism tutorial.
@winkalxy
@winkalxy 10 жыл бұрын
Your the best of best !!! Thanks alot mate
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
So setting a child class inheritance access to private (class : private ) means it'll inherit public from parent but make the public members and methods private in the child's class. So in other words this is done to keep other classes from inheriting from that child class?
@NevenaPerovic
@NevenaPerovic 10 жыл бұрын
Hey dude, I watched your Tute about Constructors and Destructors yesterday, where you created several classes - Town, Houses, People and linked them together using defined types of objects...Could you please make a comparison between that procedure and inheritance? :) What's the benefit of the later one? How can I access all the members in the previous procedure (not the inheritance), as it is super clear how I can do it here with inheritance. Thanks a lot! Cheers!
@WhatsACreel
@WhatsACreel 10 жыл бұрын
Morning, that's a good question! When you add a member variable to a class you are making a “has” relationship, houses have people, towns have houses etc. When you inherit from a parent class, you're creating an “is” relationship, a house is a building, a bee is an insect etc. Inheritance and member variables model two subtly different things. It might help to forget about the English meaning of the word Inherit. In C++, when you inherit it doesn't mean you “own” something, it means you “are” something. The difference is you can add multiple member variables of the same class, but you can't inherit from a class more than once. So, you could make a House class contain 100 People objects where the People are all member variables, a house can “have” or “own” 100 People. But with inheritance, you either inherit once or you don't. You could make a House class inherit from a Building class but you can't make a House inherit from the People class 100 times. At least that's not what inheritance is designed for. Also, inheritance allows polymorphism. We can create a Bird class which inherits from an Animal parent class. Then we can pass objects of type Bird to any methods which ask for Animal parameters. Anything Animals can do and have, Birds can do and have as well. We can treat any Bird as an Animal because a Bird is an Animal. Whereas, if a Bird has Wings as member variables, then Birds can call the public member methods of their Wings. They could call Wing.Flap() or whatever. But, a Bird object cannot be passed to a method which requests Wings as its parameter. If a method requests a Wing object as a parameter, it doesn't make sense to pass a Bird object when you call the method. Birds are not Wings even though Birds do have Wings. I hope this helps, thanks for watching and commenting and have a good one!
@NevenaPerovic
@NevenaPerovic 10 жыл бұрын
Hi :) Thanks a lot for the answer! It helped indeed a lot!!! Now I got that slight difference and I am going to test it using different examples, so to be sure that I understood you correctly. All the best and keep making such great videos ;) Cheers!
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
_getchar() is new to me. Is that similar to system (pause)? Or getline I think it was I saw in the one guys tutorial
@heeseung5
@heeseung5 7 жыл бұрын
Great explanation!
@randomthecoelho4368
@randomthecoelho4368 10 жыл бұрын
could you make a video only about game programming? using everything you taught, but only for games?
@suibora
@suibora 10 жыл бұрын
you went over it briefly but i still don't understand what it means when a class 'publicly' inherits from a parent class, the numbers mason, what do they mean?
@WhatsACreel
@WhatsACreel 10 жыл бұрын
Yes, sorry about that. I was not being very clear. I might have made the term up? Anyway, let me try and sort it out. When you inherit from a parent class, the parent will have a bunch of public members (maybe protected members as well). But the child class doesn't have to make them public when it inherits them. It can inherit them privately. That would mean that, although the members are public in the parent class, in the child class they are private. When I said "publicly inherit", I just meant that the child class used the "public" keyword in the inheritance. So anything public in the parent is also public in the child, and anything protected remains protected. It's actually a pretty strange mechanism, one of the many odd quirks of C++. I've never used anything but "public". I can imagine where you might use "private", but honestly it's not very useful. Stick to public and you're right as rain. Hope this helps, cheers!
@suibora
@suibora 10 жыл бұрын
thank you again, keep up the good work
@ChristopherJones16
@ChristopherJones16 9 жыл бұрын
+What's a Creel? I was told one should make everything private as possible. That public allows for possible problems in the future with user changing code and the such.
@facebren
@facebren 6 жыл бұрын
You are so charming, my dude
@WhatsACreel
@WhatsACreel 6 жыл бұрын
Hahaha, thank you WorldParticles, you're charming too evidently!
@OssaGhalyoun
@OssaGhalyoun 8 жыл бұрын
Good series indeed thanks. I am so glad the Chihuahua was stuffed otherwise you would have been poorer than shkit hahaha. And by the way wait for my invention of new inheritance model based on real life experience, parent instantiate a child and sets up a reverse inheritance, I will call it slurp_back constructor, hahahaha :-)
C++ Tutorial 23: Intro to Define
18:52
Creel
Рет қаралды 6 М.
C++ Tutorial 21: Polymorphism
23:39
Creel
Рет қаралды 6 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
C++ Unions
32:39
Creel
Рет қаралды 9 М.
C++ Function Pointers 1: Introduction
21:29
Creel
Рет қаралды 10 М.
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,6 МЛН
C++ Tutorial 15: Structures Explained (Game Programming)
22:36
C++ Bit Fields
30:01
Creel
Рет қаралды 15 М.
C++ Function Templates
36:02
Creel
Рет қаралды 13 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 839 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
What is INHERITANCE in C++? 👨‍👧‍👧
11:05
Bro Code
Рет қаралды 18 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН