求救,这条代码怎样理解?
这条代码怎样理解?z->scv.calc((void *)&z->scv);
搜索更多相关的解决方案:
代码
----------------解决方案--------------------------------------------------------
给你举个例子
程序代码:
#include
#include
struct _example1 {
void calc(void *);
};
struct _example2 {
struct _example1 scv;
};
void struct _example1 :: calc(void *)
{
// do something
}
int test_function( void )
{
struct _example2 *z;
z = (struct _example2 *) malloc (sizeof(struct _example2));
z->scv.calc((void *)&(z->scv));
// do something
free(z);
return 0;
}
#include
struct _example1 {
void calc(void *);
};
struct _example2 {
struct _example1 scv;
};
void struct _example1 :: calc(void *)
{
// do something
}
int test_function( void )
{
struct _example2 *z;
z = (struct _example2 *) malloc (sizeof(struct _example2));
z->scv.calc((void *)&(z->scv));
// do something
free(z);
return 0;
}
----------------解决方案--------------------------------------------------------
谢谢!
----------------解决方案--------------------------------------------------------
还不是很好理解,那位大哥帮忙注释一下!
----------------解决方案--------------------------------------------------------
#include
#include
struct _example1 {
void calc(void *); //结构体的元素是一个函数 参数是void*类型
};
struct _example2 {
struct _example1 scv; //结构体2的元素是一个结构体1
};
void struct _example1 :: calc(void *) //函数定义
{
// do something
}
int test_function( void )
{
struct _example2 *z;
z = (struct _example2 *) malloc (sizeof(struct _example2));
z->scv.calc((void *)&(z->scv)); //调用
// do something
free(z);
return 0;
}
----------------解决方案--------------------------------------------------------
重谢!
----------------解决方案--------------------------------------------------------
路过,,学习中~
----------------解决方案--------------------------------------------------------