错误:当我试图实现嵌套结构时,不允许使用不完整的类型

error: incomplete type is not allowed with when i tried to implement nested structure

本文关键字:不允许 用不完 类型 结构 嵌套 实现 错误      更新时间:2023-10-16

我试图创建一个结构,就像下面一样,它将更像嵌套结构,我已经创建了,但它抛出了一个错误,如不完整的类型是不允许的,而从结构SGebObjLst调用结构SGenObjData

struct SGenObjLst
{
    unsigned short                  objectIdx[OBJ_MAX_ID + 1][SRC_LIST_NMBR]; /* #RTAS: input               */
    struct SGenObjData              objects[OBJ_MAX_NMBR];      /* #RTAS: input               */
    unsigned short                  objNmbr;      /* #RTAS: input               */
    unsigned char                   modifiedFlag;      /* #RTAS: input               */
    unsigned char                   validFlag;      /* #RTAS: input               */
};

struct SGenObjData
{
    enum TObjType                     recogType; /* #RTAS: input               */ /* Object type (vehicle, pedestrian, ...)                                      */
    enum TObjType                     commuType; /* #RTAS: input               */ /* Object type (vehicle, pedestrian, ...)                                      */
    enum TSource                      source; /* #RTAS: input               */ /* id offset e.g. 0 for "GenericEnvObjectList" = "GEOL"                        */
    unsigned short                  id; /* #RTAS: input               */ /* object id                                                                   */
    unsigned char                   reliability; /* #RTAS: input               */ /* 0: undefined 1: very low  2: low 3: medium 4: high 5: very high             */
    unsigned char                   vulnerability; /* #RTAS: input               */ /* 0: not vulnerable (e.g. parked car), ... 5: very vulnerable (e.g. child)    */
    unsigned char                   dangerousness; /* #RTAS: input               */ /* 0: not dangerous for ego vehicle (e.g. a small bush), ... 5: very dangerous (e.g. wall)     */
    TTime                           timestamp; /* #RTAS: input, unit: us     */ /* timestamp [us]                                                              */
    TTime                           measTimestamp; /* #RTAS: input, unit: us     */ /* original measured timestamp (w/o correction due to delay time compensation) */
    float                           x; /* #RTAS: input, unit: m      */ /* x position (ego vehicle front is zero)[m]                                   */
    float                           err_x; /* #RTAS: input, unit: m      */ /* x position error [m]                                                        */
    float                           y; /* #RTAS: input, unit: m      */ /* y position (ego vehicle middle axle is zero) [m]                            */
    float                           err_y; /* #RTAS: input, unit: m      */ /* y position error [m]                                                        */
    float                           vx_rel; /* #RTAS: input, unit: m/s    */ /* relative velocity x [m/s]                                                   */
    float                           vy_rel; /* #RTAS: input, unit: m/s    */ /* relative velocity y [m/s]                                                   */
    float                           ax_rel; /* #RTAS: input, unit: m/s**2 */ /* relative acceleration x [m/s2]                                              */
    float                           vx_abs; /* #RTAS: input, unit: m/s    */ /* absolute velocity x [m/s]                                                   */
    float                           vy_abs; /* #RTAS: input, unit: m/s    */ /* absolute velocity y [m/s]                                                   */
    float                           ax_abs; /* #RTAS: input, unit: m/s**2 */ /* absolute acceleration x [m/s2]                                              */
    float                           width; /* #RTAS: input, unit: m      */ /* width of object                                                             */
    float                           err_width; /* #RTAS: input, unit: m      */ /* width error of object                                                       */
    float                           length; /* #RTAS: input, unit: m      */ /* length of object                                                            */
    float                           err_length; /* #RTAS: input, unit: m      */ /* length error of object                                                      */
    float                           height; /* #RTAS: input, unit: m      */ /* height of object                                                            */
    float                           err_height; /* #RTAS: input, unit: m      */ /* height error of object                                                      */
    float                           maxVel; /* #RTAS: input, unit: m/s    */ /* maximal speed observed during tracking                                      */
    unsigned char                   vldty_width; /* #RTAS: input               */
    unsigned char                   vldty_err_width; /* #RTAS: input               */
    unsigned char                   vldty_length; /* #RTAS: input               */
    unsigned char                   vldty_err_length; /* #RTAS: input               */
    unsigned char                   vldty_height; /* #RTAS: input               */
    unsigned char                   vldty_err_height; /* #RTAS: input               */
    unsigned char                   vldty_x; /* #RTAS: input               */
    unsigned char                   vldty_err_x; /* #RTAS: input               */
    unsigned char                   vldty_y; /* #RTAS: input               */
    unsigned char                   vldty_err_y; /* #RTAS: input               */
    unsigned char                   vldty_vx_rel; /* #RTAS: input               */
    unsigned char                   vldty_vy_rel; /* #RTAS: input               */
    unsigned char                   vldty_ax_rel; /* #RTAS: input               */
    unsigned char                   vldty_vx_abs; /* #RTAS: input               */
    unsigned char                   vldty_vy_abs; /* #RTAS: input               */
    unsigned char                   vldty_ax_abs; /* #RTAS: input               */
    unsigned char                   vldty_maxVel; /* #RTAS: input               */
};
// CREATE STRUCT 
struct SGenObjLst          objectList;
struct SGenObjData         objectData;
struct SGenDataLst                  //sundar
{
    struct SGenObjLst          objectList;
    struct SGenObjData         objectData;
};
struct SGenDataLst SGenDataLst;

您使用与类型相同的名称调用对象。您不能这样做,因为这样编译器会将类型解释为另一个声明,例如:

struct SGenDataLst SGenDataLst; // is the equivallent of:
int int;

不起作用-编译器将看到两个int并尝试声明第一个int,它将是空的-因为两个int之间没有名称,然后是另一个新的。因此,您可能会得到许多不同的错误,而唯一的问题是重复的名称。

试试这个:

struct SGenDataLst myDataList; // or any other name.

编辑:

从注释中我注意到你还以错误的顺序声明了你的结构。这也会引发与您得到的错误类似的错误,因为大多数C编译器都是反向读取的。按照amartel的建议,更改顺序,您的程序应该可以正常工作。