我今天由于业务需要 看了一下嵌入式的代码,看完之后我笑了。如果这段代码放到嵌入式的板块他们估计都会不感觉有什么稀奇的,放这里大家会感觉有点意思。
extern int fun(int x);
extern void fun1(int y);typedef struct classa {
int (*method)(int x);
void (*method1)(int y);} hello;
int main(int argc, char* argv[])
{
hello* a;
a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
int w = a->method(2);
a->method1(3);
return 0;
}
int fun(int x)
{
cout<<"methond"<<endl;
return x;
}
void fun1(int y)
{
cout<<"methond1"<<endl;
}
以上这段代码是我在对那个代码做的抽象一下,extern int fun(int x);
extern void fun1(int y);typedef struct classa {
int (*method)(int x);
void (*method1)(int y);} hello;
跟这一段跟c++里的
class classa
{public:
int method(int x);
void method1(int y);
}
做对比
接下来 hello* a;
a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
这一段跟c++里的
hello *a =new hello;
这一句做对比(其中这里a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
这3句全被隐藏的class hello 构造函数完成了
)
int w = a->method(2);
a->method1(3);与 c++中的
a->method(2);
a->method(3);
其中 a 使这个东西 hello *a =new hello;对比接下来
int fun(int x)
{
cout<<"methond"<<endl;
return x;
}
void fun1(int y)
{
cout<<"methond1"<<endl;
}
这段代码跟
int hello::fun(int x)
{};
void hello::fun1(int y)
{};
全能在功能上对应上吧,一个面向结构语言c完全实现了类和对象这个概念。
这个说明啥? 呵呵。
extern int fun(int x);
extern void fun1(int y);typedef struct classa {
int (*method)(int x);
void (*method1)(int y);} hello;
int main(int argc, char* argv[])
{
hello* a;
a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
int w = a->method(2);
a->method1(3);
return 0;
}
int fun(int x)
{
cout<<"methond"<<endl;
return x;
}
void fun1(int y)
{
cout<<"methond1"<<endl;
}
以上这段代码是我在对那个代码做的抽象一下,extern int fun(int x);
extern void fun1(int y);typedef struct classa {
int (*method)(int x);
void (*method1)(int y);} hello;
跟这一段跟c++里的
class classa
{public:
int method(int x);
void method1(int y);
}
做对比
接下来 hello* a;
a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
这一段跟c++里的
hello *a =new hello;
这一句做对比(其中这里a = (hello*)malloc(sizeof(hello));
a->method = fun;
a->method1 = fun1;
这3句全被隐藏的class hello 构造函数完成了
)
int w = a->method(2);
a->method1(3);与 c++中的
a->method(2);
a->method(3);
其中 a 使这个东西 hello *a =new hello;对比接下来
int fun(int x)
{
cout<<"methond"<<endl;
return x;
}
void fun1(int y)
{
cout<<"methond1"<<endl;
}
这段代码跟
int hello::fun(int x)
{};
void hello::fun1(int y)
{};
全能在功能上对应上吧,一个面向结构语言c完全实现了类和对象这个概念。
这个说明啥? 呵呵。
解决方案 »
- 如何阅读学习这么多的书籍?
- 这种情况是ado内存溢出吗?
- 谁会用windowsAPI做多列的列表框啊,给个提示吧。。。哭
- 我的vc出问题了,请帮帮我!!!!
- 谁知道,有oracle培训资格的公司,哪一个比较好,花公家钱当然要选好的和贵的了
- CComCoClass,CComObject中的CreateInstance,还真看不出是作什么用的?
- MFC用双缓冲画图,只能画黑白两种颜色,怎么画彩色的?
- 显示摄像头画面时有噪声
- 又一个关于api的问题来了,帮忙呀
- 如何安装ACCESS的驱动?
- 如何用VC++读取word的文档结构图或者大纲
- vc6.0下在一个Win32 Dynamic_link Library下能同时编写两个DLL文件不?
继承和多态没看到