level 7
/*
Linux下C语言完全模拟C++类
简约软件开发小组 作者:暴风
QQ:356752238
邮箱:[email protected]
2011年10月26日 19:00
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct _BUTTON Button;
//将参数传给 edx,保存地址!!
#define _this(_Gtk_gtk) asm(""::"d"(_Gtk_gtk))
//获取edx中保存的地址, 传给this保存!!
#define This_Init(_Gtk) _Gtk *this; \
asm("":"=d"(this))
Button *this(Button *t); //转换函数
void _width(int w);
struct _BUTTON
{
int button_width;
int button_height;
void (*width)();
};
Button *new_button()
{
Button *this;
this = (Button*)malloc(sizeof(Button));
this->button_width = 0;
this->button_height = 0;
this->width = _width;
return this;
}
int main(int argc, char *argv[])
{
Button *button1;
button1 = new_button();
this(button1)->width(30);
printf("button的宽度为:%d\n",button1->button_width);
return 0;
}
//转换函数
Button *this(Button *t)
{
Button *this = t;
_this(this);
return this;
}
void _width(int w)
{
This_Init(Button);
this->button_width = w;
}
2011年10月26日 11点10分
1
Linux下C语言完全模拟C++类
简约软件开发小组 作者:暴风
QQ:356752238
邮箱:[email protected]
2011年10月26日 19:00
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct _BUTTON Button;
//将参数传给 edx,保存地址!!
#define _this(_Gtk_gtk) asm(""::"d"(_Gtk_gtk))
//获取edx中保存的地址, 传给this保存!!
#define This_Init(_Gtk) _Gtk *this; \
asm("":"=d"(this))
Button *this(Button *t); //转换函数
void _width(int w);
struct _BUTTON
{
int button_width;
int button_height;
void (*width)();
};
Button *new_button()
{
Button *this;
this = (Button*)malloc(sizeof(Button));
this->button_width = 0;
this->button_height = 0;
this->width = _width;
return this;
}
int main(int argc, char *argv[])
{
Button *button1;
button1 = new_button();
this(button1)->width(30);
printf("button的宽度为:%d\n",button1->button_width);
return 0;
}
//转换函数
Button *this(Button *t)
{
Button *this = t;
_this(this);
return this;
}
void _width(int w)
{
This_Init(Button);
this->button_width = w;
}