Answer the question
In order to leave comments, you need to log in
What is the best way to program inheritance in C?
Good day.
there is a struct Base structure and a bunch of functions to it. In addition, there are definitely several types for callback functions that take a pointer to a structure as a parameter.
There was a need to extend the structure for certain functionality. But I don’t want to change the structure itself, and I don’t need to, since this functionality is not needed in other places. What to do? There are two ideas:
1) add a field pointer to void in the struct Base structure, where thirsty people can add everything extra
2) Create a type structure
struct MyCustomStruct
{
struct Base base;
t_whatever whatever;
....
}
Answer the question
In order to leave comments, you need to log in
вместо наследования имеет смысл применить макросы, ибо "наследование типов" для вашей задачи насколько я понял не нужно.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question