Struct hack equivalent in C++

前端 未结 6 2054
礼貌的吻别
礼貌的吻别 2020-12-25 12:47

The struct hack where you have an array of length 0 as the last member of a struct from C90 and C99 is well known, and with the introduction of flexible array members in C99

6条回答
  •  鱼传尺愫
    2020-12-25 13:34

    This is C++, so templates are available:

    template 
    struct hack {
        int filler;
        int thing [N];
    };
    

    Casting between different pointers to different instantiations will be the difficult issue, then.

提交回复
热议问题