c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)
生活随笔
收集整理的這篇文章主要介紹了
c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我這有個(gè)結(jié)構(gòu)體:
VENC_CHN_ATTR_S venc_chn_attr; /* the attribute of the venc chnl*/ typedef struct rkVENC_CHN_ATTR_S { //視頻編碼通道屬性結(jié)構(gòu)體VENC_ATTR_S stVencAttr; // the attribute of video encoderVENC_RC_ATTR_S stRcAttr; // the attribute of rate ctrlVENC_GOP_ATTR_S stGopAttr; // the attribute of gop } VENC_CHN_ATTR_S; /* the attribute of the Venc*/ typedef struct rkVENC_ATTR_S { //編碼參數(shù)結(jié)構(gòu)體CODEC_TYPE_E enType; // RW; the type of encodecIMAGE_TYPE_E imageType; // the type of input imageRK_U32 u32VirWidth; // stride width, same to buffer_width, must greater than// width, often set vir_width=(width+15)&(~15) //幅長(zhǎng)RK_U32 u32VirHeight; // stride height, same to buffer_height, must greater// than height, often set vir_height=(height+15)&(~15)RK_U32 u32Profile; // RW;// H.264: 66: baseline; 77:MP; 100:HP; //畫(huà)質(zhì)// H.265: default:Main;// Jpege/MJpege: default:BaselineRK_BOOL bByFrame; // RW; Range:[0,1];// get stream mode is slice mode or frame modeRK_U32 u32PicWidth; // RW; width of a picture to be encoded, in pixelRK_U32 u32PicHeight; // RW; height of a picture to be encoded, in pixelVENC_ROTATION_E enRotation;union {VENC_ATTR_H264_S stAttrH264e; // attributes of H264eVENC_ATTR_H265_S stAttrH265e; // attributes of H265eVENC_ATTR_MJPEG_S stAttrMjpege; // attributes of MjpegVENC_ATTR_JPEG_S stAttrJpege; // attributes of jpeg}; } VENC_ATTR_S;我在c++中用 = {0}初始化編譯就報(bào)錯(cuò):
VENC_CHN_ATTR_S venc_chn_attr = {0};報(bào)錯(cuò):
error: invalid conversion from ‘int’ to ‘CODEC_TYPE_E’ {aka ‘rk_CODEC_TYPE_E’} [-fpermissive]VENC_CHN_ATTR_S venc_chn_attr = {0};用memset函數(shù)就能正常編譯通過(guò):
memset(&venc_chn_attr, 0, sizeof(VENC_CHN_ATTR_S));而在c中用 = {0}是可以正常編譯過(guò)的,到了c++里就不行了。。
原因,c++中結(jié)構(gòu)體不能用 = {0}來(lái)初始化,要用 = {}來(lái)初始化
參考文章:c++中結(jié)構(gòu)體中套結(jié)構(gòu)體不能用 = {0}來(lái)初始化嗎? - 知乎
總結(jié)
以上是生活随笔為你收集整理的c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: arm linux c++编译警告:IS
- 下一篇: C语言怎么开辟超大内存?(malloc)