在标准 C 或 C++ 中是否可以继承另一个结构?
最佳答案
你可以在另一个结构中嵌入一个结构来模拟 C 中的继承:
typedef struct {
int i;
} base;
void basefunc(base *b);
typedef struct {
base b;
char c;
} extended;
extended e;
/* Initialise extended here */
basefunc(&e.b); /* Use the type checker */
basefunc((base*)&e); /* Just make sure you know what you're doing */
关于c++ - C中的结构继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4118899/