C++中结构体嵌套,如何new分配内存?

1.C++中结构体多层嵌套,如果使用new动态分配内存?

结构体定义如下:

typedef struct _STR_POINT2F

{

    float fX;

    float fY;

}STR_POINT2F;

typedef struct _STR_LONLAT

{

    double dLon;

    double dLat;

}STR_LONLAT;

typedef struct _STR_POLYGON

{

    int iCount;

    STR_POINT2F *pstrPoint;

}STR_POLYGON;

typedef struct _STR_SPACE

{

    float fTheta;

    STR_POINT2F pstrPoint[4];

}STR_SPACE;

typedef struct _STR_LINE

{

    int iId;

    STR_POINT2F pstrPoint[2];

}STR_LINE;

typedef struct _STR_STATION

{

int iId;

    STR_POINT2F strLocation;

    STR_POLYGON strPolygon;

    int iCount;

    STR_SPACE *pstrSpace;

}STR_STATION;

typedef struct _STR_ID

{

    int iId; /* ID */

    int iCountCenter;   /* 数量 */

    STR_POINT5f_LANE_CENTER_POINT *pstrCenter; /* 信息 */

    float fWidth; /* 宽度 */

    EM_LANE_TYPE emType;    /* 类型 */

    int iCountIncome;   /* 后方ID数量 */

    int *piIncomeId;    /* 后方ID列表 */

}STR_ID;


typedef struct _STR_TEST

{

    char Num[15];

    STR_LONLAT strLonLat; /* 经纬度 */

    int iCountStation;  /* 结构体STR_STATION的数量 */

    STR_STATION *pstrStation;   /* 信息 */

    int iCountId;   /* 结构体STR_ID的数量 */

    STR_ID *pstrId; /* 信息 */

    int iCountLine; /* 数量 */

    STR_LINE *pstrLine; /* 信息 */

}STR_TEST;

2.现要给结构体STR_TEST 分配内存,请问,如何使用new来动态分配?

STR_TEST * st = new STR_TEST;
st.STR_STATION = new STR_STATION;
...