69,371
社区成员
发帖
与我相关
我的任务
分享
typedef struct
{
int a, b;
int *(max)(int,int);
}
Func;
int max(int a, int b)
/*
* 如何让这个函数不需要参数也能获得结构体中的a和b这两个变量?
**/
{
return a>b ? a:b;
}
int main()
{
Func f;
f.max = max;
f.a = 100;
f.b = 50;
printf("max: %d\n", f.max(f.a, f.b));
/*
* 以上一段代码是这样的,我想让它这样也能输出同样的结果:
* printf("max: %d\n", f.max());
* 不直接传参数给函数,能实现吗?
**/
return 0;
}
#include <stdio.h>
typedef struct Func_t
{
int a, b;
int max() {
return a>b ? a:b;
}
} Func;
int main()
{
Func f;
// f.max = max;
f.a = 99;
f.b = 50;
printf("max: %d\n", f.max());
/*
* 以上一段代码是这样的,我想让它这样也能输出同样的结果:
* printf("max: %d\n", f.max());
* 不直接传参数给函数,能实现吗?
**/
return 0;
}
#include <stdio.h>
typedef struct Func_t
{
int a, b;
int max(int a, int b) {
return a>b ? a:b;
}
} Func;
int main()
{
Func f;
// f.max = max;
f.a = 100;
f.b = 50;
printf("max: %d\n", f.max(f.a, f.b));
/*
* 以上一段代码是这样的,我想让它这样也能输出同样的结果:
* printf("max: %d\n", f.max());
* 不直接传参数给函数,能实现吗?
**/
return 0;
}
typedef struct _Func
{
int a, b;
int (*max)(struct _Func*);
}
Func, *PFunc;
int max(PFunc f)
/*
* 如何让这个函数不需要参数也能获得结构体中的a和b这两个变量?
**/
{
return f->a > f->b ? f->a : f->b;
}
int main()
{
Func f;
f.max = max;
f.a = 100;
f.b = 50;
printf("max: %d\n", f.max(&f));
/*
* 以上一段代码是这样的,我想让它这样也能输出同样的结果:
* printf("max: %d\n", f.max());
* 不直接传参数给函数,能实现吗?
**/
return 0;
}
window::resize(100, 300);
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
w.show();
return a.exec();
}