我有这个结构:
typedef struct s_hashmap
{
t_hashmap_elem **array_elements;
size_t array_size;
void *(*get)(struct s_hashmap **, void *);
void (*add)(struct s_hashmap **, t_hashmap_elem *);
} t_hashmap;
我可以在获取函数指针时访问 array_elements 而无需像这样将我的变量作为参数传递吗:
h->get(&h, &key); // h is the t_hashmap variable.
如果这不可能,请向我解释另一种方法。
提前致谢。
最佳答案
不,你不能。 C 中没有用户定义类型的方法。如果要更改它,必须将指针(或指向指针的指针,具体取决于参数声明)传递给结构的对象。
关于c - 从同一结构中的函数指针访问变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34956924/