69,376
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include "oopc.h"
CLASS(HelloWorld)
{
OOPC;
bool (*test)(bool b);
};
static bool test(bool b)
{
b ? printf("Hello World!\n") : printf("Hello China!\n");
return !b;
}
CTOR(HelloWorld)
{
printf("ctor\n");
BIND(test);
}
DTOR(HelloWorld)
{
UNUSED(self);
printf("dtor\n");
}
int main()
{
HelloWorld *p = new(HelloWorld);
p->test(!false);
delete(p);
return 0;
}
project(demo_01)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
set(CMAKE_BUILD_TYPE Debug)
include_directories(..)
add_executable(demo_01 ${SRC_LIST})
ABS_CLASS(Global)
{
...
} _global;
static __attribute((constructor)) void appConstructor()
{
ctorGlobal(&_global);
}
static __attribute((destructor)) void appDestructor()
{
dtorGlobal(&_global);
}
#undef M
#define M (*_global._memberVariable)