:
내 주요 문제는 현재 다음과 같이 내 게임 클래스의 기능을 많이 가지고있다. 아아, 사용하는 프로그래밍 언어를 제공하지 않습니다. 당신은 C로 프로그래밍하는 경우
예를 들어, 당신은 할 수
struct thefunctions {
void (*stuff1)(void);
void (*stuff2)(int);
int (*get)(int);
};
struct thefunctions network {
.stuff1 = doSomething;
}
struct thefunctions standalone {
.stuff1 = doSomethingCompletelyDifferent;
}
struct thefunctions * funcs;
[...]
if (host) {
funcs = &network;
} else {
funcs = &standalone;
}
// now the structs are initialized. We can now use funcs->.
[...]
// If I am sure that stuff1 has been initialited properly, I can do
funcs->stuff1();
// If not, I should check first
if (funcs->stuff1) funcs->stuff1();
// or
assert(funcs->stuff1);
funcs->stuff1();