Handmade Hero»Forums»Code
Ian Hern
8 posts
Day 89 - Why not use Inheritance?
For some reason I can't make a new post in the Code Discussion so I brought this here. Why not use inheritance for the render entries?
Mārtiņš Možeiko
2562 posts / 2 projects
Day 89 - Why not use Inheritance?
Edited by Mārtiņš Možeiko on
Because there is not such thing in C. Inheritance is OOP thingy in C++. Well, you could simulate inheritance in C with structures and function pointer, but it will get ugly very fast (for example look in these files: https://github.com/tracy/AtomixMi....2.4/Source/Core/AtxStreams.h#L32 and https://github.com/tracy/AtomixMi...e/System/Win32/AtxWin32File.c#L36 where Win32FileStream inherits from other "classes").

But if you are actually asking why not use C++ and inheritance, then to that Casey has answered multiple times why he doesn't like C++. Using inheritance would require to deal with constructors, destructors, "new" operator for memory allocation (or object placement) and all the other C++ stuff...
popcorn
70 posts
Day 89 - Why not use Inheritance?
Edited by popcorn on
As Casey said Inheritance can make thing more confusing than it should. It's true, Although, I still use it in some cases but, in the past I found what he said to be some what true.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 89 - Why not use Inheritance?
The answer is because it doesn't actually do anything. The difference between writing

struct clear : public header {...};

and

struct clear {header Header;}

is strictly that you don't type ".Header." in a few places.

As foreshadowed by the TODO I put in there in today's stream, we will be getting read of the header part entirely very shortly - it's an intermediate thing, not a permanent thing.

- Casey