To encapsulate the class, and make methods be able to apply directly on an object, we need the following design, a constructor that has the attributes as pointers to functions, for example

struct Map *Map_new() {
    struct Map *p = malloc(sizeof(*p));

    p->__head = NULL;
    p->__tail = NULL;
    p->__count = 0;
    p->put = &__Map_put;
    p->get = &__Map_get;
    p->size = &__Map_size;
    p->dump = &__Map_dump;
    p->del = &__Map_del;
    p->iter = &__Map_iter;
    return p;
}

Resources

Yiming Zhang
Yiming Zhang
Quantitative Researcher Associate, JP Morgan