【发布时间】:2011-08-27 02:20:55
【问题描述】:
假设我有以下代码:
struct test* t1;
t1 = get_t(1);
...get_t 是:
struct test* get_t(int);
如何重构上述代码并将其放入函数中?类似于以下内容:
void r1(?* t, ?* (fn*)(int)) {
t = fn(1);
}
/* ... */
struct test* t1;
r1(t1, &get_t);
【问题讨论】:
-
你可以使用
void r1(struct test* t, struct test* (fn*)(int))...为什么是未知类型的参数? -
因为我想为
struct another_test使用相同的函数。就像我拥有struct test* t1并使用r1(t1, &get_t)一样,我也希望能够拥有struct another_test* t2并使用r1(t2, &get_at),其中get_at返回struct another_test*,并执行相同的操作来获取它。跨度>