是否可以像 Python 一样在 C (OOP) 中实现点表示法?
类似于:
struct myClass {
...
...
}
然后在该结构上有一个方法,例如:
myClass.someMethod();
最佳答案
是的,someMethod()
将是一个函数指针:
#include <stdio.h>
typedef struct
{
void (*someMethod) (void);
}Test;
void asd (void)
{
printf("works");
}
int main(void)
{
Test test;
test.someMethod = asd;
test.someMethod(); // will print works
}
关于c - C 中的点表示法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50373748/