cozhzh 2019-02-18 18:42 采纳率: 0%
浏览 1326

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来动态分配?

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-02-18 23:46
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?