I'm working on implementing a dynamic linked list in C to refresh my C skills. Here is a simple structure that I use to represent LinkedList:
typedef struct List { Node_t* head; Node_t* tail; uint32_t length; void (*add)(Node_t* head, void* data); } List_t;
I write all this in my own C file with the hope that I can include it in some other C file and use the linked list implementation I wrote.
You will notice that I have a pointer to a function that will add node to the linked list. (I have several functions besides adding, but I just wanted to parse this first)
If I were to use this linked list now, I would have to call it like this
List_t* list = GetList(); list->add(list->head, someData);
Is it possible to encode it in OO style, so all I need to do is call:
list->add(someData);
Without going to the top of the add () function list? My instincts tell me this is not possible, but I really like the idea of ββmaking my linked lists work this way.
-Akron
Edit: Fixed link to add to reflect the fact that the list is a pointer
Edit: It seems the general consensus is not. Thanks for the tips / answers.
source share