No video

C++ Polymorphism and Virtual Member Functions [6]

  Рет қаралды 11,844

Professor Hank Stalica

Professor Hank Stalica

Күн бұрын

In object-oriented programming, polymorphism enables object reference variables or pointers to reference objects of different types, and to invoke the appropriate member functions based on the type of object being referenced.
Learn how through writing sample classes in this C++ tutorial for beginners written with Visual Studio 2022 C++ .
// Join the new Programming for Everyone Community Forum:
professorhank....
// Learn More //
The Inheritance, Polymorphism,and Virtual Functions play list:
• CH15: Inheritance, Pol...
// Consider supporting this channel in multiple ways
paypal.me/hank...
Bitcoin: 177wfkQwzXiC8o2whQMVpSyuWUs95krKYB

Пікірлер: 21
@orionpluto1214
@orionpluto1214 4 ай бұрын
The best explanation I've found on this subject, thank you very much !
@saramomen2161
@saramomen2161 9 ай бұрын
You explained too well. Tomorrow is my exam and I understood the topic completely. Thank you.
@ProfessorHankStalica
@ProfessorHankStalica 9 ай бұрын
Glad it helped!
@dwivedys
@dwivedys 4 ай бұрын
Absolutely wonderful!
@Johannes-vr3vc
@Johannes-vr3vc 6 ай бұрын
Some time ago, when I used g++, I could type something like this: Square *s = (class Square*)&r; I think this will probably still work and maybe it explains things better.
@lg7t
@lg7t Ай бұрын
so why did we make all the destrcutors virtual should not that be just for the base class or we did it for readbilty of the code ?
@ProfessorHankStalica
@ProfessorHankStalica 28 күн бұрын
Best practice to make them virtual in case the class is derived from in the future.
@manedurphy
@manedurphy Жыл бұрын
class Foo { void print() const { cout
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
It means that the print() function can not contain any code that modifies class member variables. If print were to try, the compiler will give you an error at compile time. For example, class Foo { int x; void print() const { x = 0; cout
@manedurphy
@manedurphy Жыл бұрын
@@ProfessorHankStalica thank you for explaining. new subscriber 🤝
@AlexTrouman-oi1yp
@AlexTrouman-oi1yp 9 ай бұрын
Mr.Hank please what is the difference betwen ~square(){}; and virtuel ~square(){}; .Thanks for your explanation
@ProfessorHankStalica
@ProfessorHankStalica 9 ай бұрын
It's the difference between using static binding and dynamic binding. If you want C++ to decide which method to use at runtime, you use dynamic binding (virtual), otherwise you use static binding. Sometimes C++ has to decide which destructor to use at run time. Basically, if you expect your class will ever be inherited from, you should make the destructor virtual.
@egetan9247
@egetan9247 8 ай бұрын
Sir , I did not understand something , which is ; Why we put virtual for all destructors meanwhile put virtual for only base class's print function . Thank you for considering :)
@ProfessorHankStalica
@ProfessorHankStalica 8 ай бұрын
You use virtual on methods that you expect will be overridden in child classes. If there is a chance your class gets inherited from, then it's a good practice to make destructors virtual. That way, if the classes get used in a polymorphic context, you ensure the correct destructor is executed for each object.
@egetan9247
@egetan9247 8 ай бұрын
@@ProfessorHankStalica thank you so much.. :)
@bashiraddean-mufarreh
@bashiraddean-mufarreh Жыл бұрын
im first watching 🤓first like 👍🏻
@menachemlevi
@menachemlevi 7 ай бұрын
amazing keep going
@ProfessorHankStalica
@ProfessorHankStalica 7 ай бұрын
Thank you, I will
@user-hq2pc5yz6p
@user-hq2pc5yz6p 8 ай бұрын
what if we did r.print()
@massimoazzano
@massimoazzano 7 ай бұрын
I like you use a geometric example, people like me can visualize the proposed problem, meaning and scope!
@jesuschrist1501
@jesuschrist1501 8 ай бұрын
yea but why the hell would you ever need to use all this shyt, keep it simple and readable.
C++ Abstract base classes and pure virtual functions [7]
7:09
Professor Hank Stalica
Рет қаралды 4,7 М.
C++ Tutorial: Finding Classes and their Responsibilities [10]
11:58
Professor Hank Stalica
Рет қаралды 453
SCHOOLBOY. Мама флексит 🫣👩🏻
00:41
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 6 МЛН
When you discover a family secret
00:59
im_siowei
Рет қаралды 32 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 64 МЛН
Just Give me my Money!
00:18
GL Show Russian
Рет қаралды 1000 М.
How Magnus Calmly DESTROYED His "Rivalry" with Hans Niemann
9:51
TightKnights
Рет қаралды 42 М.
Dynamic Binding (Polymorphism) With The Virtual Keyword | C++ Tutorial
9:57
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,5 МЛН
C++ OOP - What is inheritance in programming?
16:32
CodeBeauty
Рет қаралды 141 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,2 МЛН
SCHOOLBOY. Мама флексит 🫣👩🏻
00:41
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 6 МЛН