可以像这样在 C 中模仿命名空间:
#include <stdio.h>
#include <math.h>
struct math_namespace {
double (*sin)(double);
};
const struct math_namespace math = {sin};
int main() {
printf("%f\n", math.sin(3));
return 0;
}
这有什么缺点,或者只是前缀更有意义的情况?这样做似乎更干净。