typedef struct Base
{
int a, b, c;
}Base;
typedef struct Sub
{
int a, b, c, d;
char *str;
}Sub;
int main()
{
Base *b;
Sub *s;
b = new Base;
s = (Sub*)b;
s->str = new char[100];
return 0;
}
...全文
2755打赏收藏
新手求助结构体指针问题
我定义了两个结构体,对它们进行了内存分配,却不知道如何对应回收,可否请教? typedef struct Base { int a, b, c; }Base; typedef struct Sub { int a, b, c, d; char *str; }Sub; int main() { Base *b; Sub *s; b = new Base; s = (Sub*)b; s->str = new char[100]; return 0; }