Converting code from c to c++ -
this question has answer here:
i'm trying convert code c c++ project using raspberry pi camera module , i'd analyse pictures it.
but on piece of code (somebody else created) error
231:8: error: expected primary-expression before ‘.’ token
which line:
.max_stills_w = state->width,
i tried find keeps giving me other errors
video_port = camera->output[mmal_camera_video_port]; still_port = camera->output[mmal_camera_capture_port]; // set 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 encode format on video port
the named structure member initialisation in c99 not implemented in c++. in c++ can perform member initialisation using constructor. e.g:
struct sconfig { int m_x ; int m_y ; sconfig( int x, int y ) : m_x(x), m_y(y) {} } ;
or:
struct sconfig { int m_x ; int m_y ; sconfig( int x, int y ) { m_x = x ; m_y = y ; } } ;
or combination of 2 methods. instantiate object thus:
sconfig myconfig( 10, 20 ) ;
initialising m_x
, m_y
10 , 20 respectively in example.
you can of course perform initialisation provided structures defined constructors; not bad thing - letting user arbitrarily decide members initialise not particularly safe or maintainable. can of course define multiple constructors perform different initialisations; want define default constructor example:
struct sconfig { int m_x ; int m_y ; sconfig( int x, int y ) : m_x(x), m_y(y) {} sconfig( ) : m_x(0), m_y(0) {} } ;
so in example:
sconfig myconfig ;
is equivalent of following:
sconfig myconfig( 0, 0 ) ; sconfig myconfig = { 0, 0 } ; sconfig myconfig = {0} ;
Comments
Post a Comment