Very good. First, the question may not be in the correct format. I will modify it as I add more information or the comments show a lack of information or structure.
I have a structure made of POD, in C99.
I will give an example of the type of structure in which I usually find the one that interests me (kindly extract Freetype 2.4.4):
typedef enum BDF_PropertyType_
BDF_PROPERTY_TYPE_NONE = 0,
BDF_PROPERTY_TYPE_ATOM = 1,
BDF_PROPERTY_TYPE_INTEGER = 2,
BDF_PROPERTY_TYPE_CARDINAL = 3
typedef struct BDF_PropertyRec_
const char * atom;
My question is: How to get a wrapper in C ++ 98 to interconnected structures?
I planned to do a course that used a
BDF_PropertyRecbut using it as a private object and using it, but I still depend on
free for its life cycle, quickly abandoning the idea by keeping in mind the two objects, as they do here: https://os.mbed.com/questions/241/How-to-wrap-C-functions -into-C -class /
Here, https://stackoverflow.com/a/17454763/8607301, apply a form of the inheritance type to get a wrapper. I do not see how to achieve this with POD structures or classical data that have pointers connected to other structures, or a vector of these elements given by the base pointer and the maximum length, something like this:
typedef struct t_Elements_used
} * Elements_used; // Look at the pointer element, here it is cheating!
typedef struct t_Structura_POD_con_vectores
Vector elements used; // It's cheating, read the definition of the previous typedef well!
} Structure_POD_with_vectors; // <How to integrate this in a class?
In software engineering (https://softwareengineering.stackexchange.com/q/181587/296879), they comment with the help of facades or
std :: make_unique. In the case of C ++ 98,
std :: make_unique it does not work (you have to insert the extension TR1 or use boost, and for the moment, it is not viable), and a facade pattern adds too many layers to access the elements of this vector, which makes the difficult encapsulation (one layer for the first structure, another for the second and one for the communication between the two, leaving the original structure duplicated, but I do not see that it is accessible without copies.
As I read in Coding Standards C ++ – 101 Rules, Guidelines and Best Practices, from Herb Sutter and Andrei Alexandrescu, recommends the use of RAII (Recommendation 13), which involves duplicating and to maintain the two objects, the structure and the object. C ++ converted.
I repeat the question: How to create a wrapper in C ++ 98 (obsolete!) For a structure connected to others in C99?