How do you implement OOP in C Programming Language

preview_player
Показать описание
OOP (Object-Oriented Programming) is a widely used Programming Concept, but it is missing in the Vanilla C Programming Language. This video, demonstrates how you can implement an OOP like modularity in the C Programming Language with the help of structure.
Рекомендации по теме
Комментарии
Автор

If you still have to pass the structure pointer inside the parenthesis then there's NO point to this. Might as well go the normal route and just call the function without doing struct.get

princesschelsea
Автор

I haven't checked the latest C or C++ standards but about 15 years ago the only formal difference between a struct and a class is that by default everything within a struct is public while everything within a class is private.

WrinkledHound
Автор

This is awesome I wish you could make a video longer explain in more detail because as its is like 10 sec explanation per section.

rul
Автор

You can also do
struct Person p1 = {&setAge, &getAge};

solonton
Автор

that actually is amazing, but I think that you can actually create constructors (and subsequently, destructors), by include all of the function bindings in the init() function. The destructor can be simple, by calling the free() function.

quanquoctruong
Автор

OOP is a paradigm, the looks of the code don't matter. Thus, adding function pointers into the struct definition in order to make it look like C++ is a very stupid idea. You loose on optimizations that the compiler might make. See how the FILE and related functions are implemented in C, it's all OO but does not look like C++. All concepts of OOP can be implemented in C, just that it won't look like C++. If looks of the code matter to you then use C++. There is no way C can give you that!

rajdivecha
Автор

I know that a C++ precompiler does this, kinda the same behind the scene. And I wanted to say that what happens to inheritance? How can I make the same?

relytheone
Автор

Do we need to define the function pointers inside struct? Is it better just to use the function with the instance without the funciton pointer?

slowcoding
Автор

forget const and static in files, for encapsulation

juniorlucival
Автор

No it is not OOP. all the function pointer etc is okay but, when you make p1.set, you shouldn't make &p1, when you do that, it became normal function, in this case, this function is just bonded, not a class function. but thanks for the video.

furkanayas
Автор

Have to specify the instance = 4 minutes of nothing. You should really remove “OOP” from the title 👎

ba-ba-ba-barspin