日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)

發布時間:2025/3/20 c/c++ 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我這有個結構體:

VENC_CHN_ATTR_S venc_chn_attr; /* the attribute of the venc chnl*/ typedef struct rkVENC_CHN_ATTR_S { //視頻編碼通道屬性結構體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 { //編碼參數結構體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) //幅長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; //畫質// 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}初始化編譯就報錯:

VENC_CHN_ATTR_S venc_chn_attr = {0};

報錯:

error: invalid conversion from ‘int’ to ‘CODEC_TYPE_E’ {aka ‘rk_CODEC_TYPE_E’} [-fpermissive]VENC_CHN_ATTR_S venc_chn_attr = {0};

用memset函數就能正常編譯通過:

memset(&venc_chn_attr, 0, sizeof(VENC_CHN_ATTR_S));

而在c中用 = {0}是可以正常編譯過的,到了c++里就不行了。。

原因,c++中結構體不能用 = {0}來初始化,要用 = {}來初始化

參考文章:c++中結構體中套結構體不能用 = {0}來初始化嗎? - 知乎

總結

以上是生活随笔為你收集整理的c++中结构体套结构体用 = {0}初始化编译报错解决办法(用memset或者={})(error: invalid conversion)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。