OOC - Base

menos que 1 minuto(s) de leitura

Como utilizar OOC?

There are many ways to achieve object orientation in C. We will follow the approach used by Axel-Tobias Schreiner in his Object-Oriented Programming With ANSI-C book. In it we use hidden structs, void pointers, variatic functions and dynamic linkage to achieve object orientation.

One of the main differences of our method is that we will not be using a different preprocessor for our development. We will use the C preprocessor and MACROS to facilitate our development.

It’s really simple to starting using it, you just have to get the code for the base classes, the macros and some simple classes and interfaces and include what you will really use.

#include "vector.h"
int main(){
    o_Vector o_int_vector = VectorC(int);
    Collection_inplaceAddAllC(o_string_vector, int, ARG({1, 2, 3, 4}));
    o_Iterator o_iterator = Iterable_create(o_int_vector);
    Collection_add(INT(5));
    Collection_add(INT(6));
    for_iterator(o_iterator){
        int* p_int = Iterator_currItem(o_iterator);
        if(p_int){
            printf("%d,", *p_int); // Will print out 1,2,3,4,5,6,
        }
    }
    printf("\n");
    OOC_DELETE(o_iterator);
    OOC_DELETE(o_int_vector);
}

Tags: ,

Categorias:

Atualizado em:

Deixe um comentário