example using a base handle for structs in C++
// Example program
#include <iostream>
//pointer to doubly linked list object in C
//extends cpp structs with base macros
#define Base_HANDLE int type; \
struct Base* next; \
struct Base* prev;
struct Base
{
Base_HANDLE
};
struct IntObj
{
Base_HANDLE
long value;
};
void printType(Base* b)
{
std::cout << b->type << std::endl;
}
void connect(Base* b1, Base* b2)
{
b1->next = b2;
b2->prev = b1;
}
int main()
{
IntObj* i = new IntObj();
i->type = 3;
i->value = 500;
IntObj* j = new IntObj();
j->type = 3;
j->value = 500;
Base* b = (Base*)i;
std::cout << b->type << std::endl;
printType(b);
//3
//3
connect((Base*)i, (Base*)j);
std::cout << ((IntObj*)i->next)->value << std::endl;
//500
delete i;
delete j;
}