Code/Recipes/C OOP

From Polytech Center Barcelona
Jump to: navigation, search
#include <string.h>

struct person_t {
    char name[24];
    int age;
};

person_t* new_person(const char* name, int age)
{
    person_t* self = new person_t;
    strncpy(self->name, name, 24);
    self->age = age;
    return self;
}

void destroy_person(person_t** self)
{
    delete *self;
    self = 0;
}

bool person__is_valid_age(person_t* self)
{
    if age > 18:
        return true;
    return false;
}