我想一些代碼由C轉換爲C++ 這是一個用帶攝像頭模塊樹莓派一個項目,我想分析的圖片吧。從C代碼轉換到C++
但在這一段代碼(別人創建)我得到這個錯誤
231:8: error: expected primary-expression before ‘.’ token
這是這一行:
.max_stills_w = state->width,
我嘗試了所有我能找到,但它一直給我其他錯誤
video_port = camera->output[MMAL_CAMERA_VIDEO_PORT];
still_port = camera->output[MMAL_CAMERA_CAPTURE_PORT];
// set up the camera configuration
{
MMAL_PARAMETER_CAMERA_CONFIG_T cam_config =
{
{ MMAL_PARAMETER_CAMERA_CONFIG, sizeof(cam_config) },
.max_stills_w = state->width,
.max_stills_h = state->height,
.stills_yuv422 = 0,
.one_shot_stills = 0,
.max_preview_video_w = state->width,
.max_preview_video_h = state->height,
.num_preview_video_frames = 3,
.stills_capture_circular_buffer_height = 0,
.fast_preview_resume = 0,
.use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RESET_STC
};
mmal_port_parameter_set(camera->control, &cam_config.hdr);
}
// Set the encode format on the video port
這是一個C99功能,不可用C++編寫。你只需實例化你的'struct'變量,然後賦值給指定的成員,你不能用寫成的名字成員來初始化。 – CoryKramer
@Cyber這個問題是否解釋瞭如何在C++中進行等價處理?如果不是,它不是重複的。 – Barmar
您不應該轉換工作的C代碼。我建議用C++包裝C代碼(如果它有開發/維護的好處) –