69,394
社区成员
发帖
与我相关
我的任务
分享
main.c|231|error C2275: 'IntListData' : illegal use of this type as an expression|
main.c|231|error C2065: 'p' : undeclared identifier|
main.c|231|error C2065: 'p' : undeclared identifier|
main.c|231|error C2223: left of '->data' must point to struct/union|
main.c|231|error C2065: 'p' : undeclared identifier|
main.c|231|error C2223: left of '->next' must point to struct/union|
main.c|231|error C2065: 'p' : undeclared identifier|
main.c|231|warning C4047: '=' : 'IntListData *' differs in levels of indirection from 'int'|
main.c|232|error C2275: 'VoidPtrListData' : illegal use of this type as an expression|
main.c|232|error C2065: 'p' : undeclared identifier|
main.c|232|error C2065: 'p' : undeclared identifier|
main.c|232|error C2223: left of '->data' must point to struct/union|
main.c|232|error C2065: 'p' : undeclared identifier|
main.c|232|error C2223: left of '->next' must point to struct/union|
main.c|232|error C2065: 'p' : undeclared identifier|
main.c|232|warning C4047: '=' : 'VoidPtrListData *' differs in levels of indirection from 'int'|
main.c|239|error C2275: 'VoidPtrList' : illegal use of this type as an expression|
main.c|239|error C2065: 'vl' : undeclared identifier|
main.c|240|error C2065: 'vl' : undeclared identifier|
main.c|240|error C2223: left of '->pushBack' must point to struct/union|
main.c|240|error C2065: 'vl' : undeclared identifier|
main.c|241|error C2065: 'vl' : undeclared identifier|
main.c|241|error C2065: 'vl' : undeclared identifier|
main.c|241|warning C4022: 'function through pointer' : pointer mismatch for actual parameter 1|
main.c|241|error C2065: 'vl' : undeclared identifier|
||=== Build finished: 22 errors, 3 warnings (0 minutes, 0 seconds) ===|
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <memory.h>
// bool support
enum bool { false, true };
typedef enum bool bool;
// avoid unused warning
#define UNUSED(x) (void)(x)
// delete self
#define OOPC \
void (*delete)(void*)
// Base class
struct Class { OOPC; };
typedef struct Class Class;
// new/delete
#define new(selfClass) new##selfClass()
#define delete(self) \
((Class *)self)->delete(self); \
self = 0
// Abstract Class
#define ABS_CLASS(selfClass) \
typedef struct selfClass selfClass; \
void ctor##selfClass(selfClass *self); \
void dtor##selfClass(selfClass *self); \
struct selfClass
// Class
#define CLASS(selfClass) \
typedef struct selfClass selfClass; \
selfClass* new##selfClass(); \
void delete##selfClass(void *self); \
void ctor##selfClass(selfClass *self); \
void dtor##selfClass(selfClass *self); \
struct selfClass
// Constructor / Implemention new##selfClass
#define CTOR(selfClass) \
selfClass* new##selfClass() { \
selfClass *self = (selfClass *)malloc(sizeof(selfClass)); \
if (!self) \
return 0; \
ctor##selfClass(self); \
BIND_D(delete, delete##selfClass); \
return self; \
} \
void ctor##selfClass(selfClass *self)
#define ABS_CTOR(selfClass) \
void ctor##selfClass(selfClass *self)
#define FATHER_CTOR(fatherClass) \
ctor##fatherClass(F(self, fatherClass))
// Destructor / Implemention delete##selfClass
#define DTOR(selfClass) \
void delete##selfClass(void *self) { \
dtor##selfClass(self); \
free(self); \
} \
void dtor##selfClass(selfClass *self)
#define ABS_DTOR(selfClass) \
void dtor##selfClass(selfClass *self)
#define FATHER_DTOR(fatherClass) \
dtor##fatherClass(F(self, fatherClass))
// Bind member function
#define BIND(selfFunc) \
self->selfFunc = selfFunc
// Bind to Different name function
#define BIND_D(selfFunc, staticFunc) \
self->selfFunc = staticFunc
// Bind to Father's member
#define BIND_F(fatherClass, staticFunc) \
self->fatherClass.staticFunc = staticFunc
// Inheritance
#define INHERIT(fatherClass) \
struct fatherClass fatherClass
// Get Father Pointer
#define F(self, fatherClass) \
((fatherClass *)(&(self->fatherClass)))
#define FF(self, fatherClass, grandfatherClass) \
F(F(self, fatherClass), grandfatherClass)
// Get Son Pointer
#define S(self, selfClass, sonClass) \
((sonClass*)((char *)self - offsetof(sonClass, selfClass)))
#define SS(self, selfClass, sonClass, grandsonClass) \
S(S(self, selfClass, sonClass), sonClass, grandsonClass)
// Information hiding for member variables
#define MEMBER_DECL(selfClass) \
struct selfClass##Member *_memberVariable
#define MEMBER_IMPL(selfClass) \
struct selfClass##Member
#define MEMBER_IMPL(selfClass) \
struct selfClass##Member
#define MEMBER_INIT(selfClass) \
self->_memberVariable = malloc(sizeof(struct selfClass##Member)); \
memset(self->_memberVariable, 0, sizeof(struct selfClass##Member))
#define MEMBER_FREE() \
free(self->_memberVariable); \
self->_memberVariable = 0
#define M \
(*self->_memberVariable)
int main()
{
IntList *il = new(IntList);
VoidPtrList *vl;
il->pushBack(il, 2);
delete(il);
/* VoidPtrList **/vl = new(VoidPtrList);
vl->pushBack(vl, main);
delete(vl);
return 0;
}