c++ - Argument of type “const [structname] *” is incompatible with parameter of type “const [structname] *” -


i trying include structure in library function in c++.

the structure goes this:

struct net_in_operate_facerecongnitiondb{ dword                             dwsize; em_operate_facerecongnitiondb_type    emoperatetype; facerecognition_person_info       stpersoninfo; char                              *pbuffer; int                               nbufferlen; };                                                ` 

and function in included goes this:

bool client_operatefacerecognitiondb(  llong                             lloginid,  const net_in_operate_facerecongnitiondb      *pstinparam,  net_out_operate_facerecongnitiondb      *pstoutparam,  int                                 nwaittime = 1000,  ); 

i'm defining structure pointer writing following lines:

const struct net_out_operate_facerecongnitiondb{     dword                             dwsize = sizeof(net_in_operate_facerecongnitiondb);     em_operate_facerecongnitiondb_type    emoperatetype = net_facerecongnitiondb_add;     facerecognition_person_info       facerecognition_person_info1;     char                              *pbuffer = '\0';     int                               nbufferlen = 10; } *pstinparam; 

but when call structure function using line:

client_operatefacerecognitiondb(m_loginid, pstinparam, pstoutparam, 1000); 

i getting error saying

argument of type “const net_in_operate_facerecongnitiondb *” incompatible parameter of type “const net_in_operate_facerecongnitiondb *”

this unusual, because both argument , parameter of same type. mistake have done?

this unusual, because both argument , parameter of same type.

they not of same type (which error message tells you, though not helpful in doing so).

what's going on here declaration of pstinparam in fact defining anonymous struct, , introducing variable pointer anonymous struct.

this more readily seen in reduced example, yields more helpful error on recent gcc versions:

struct some_struct {   int member; };  bool some_function(const some_struct*) {  return false;    }  int main() {   const struct some_struct {     int member = 0;   } *param;    some_function(param); } 
prog.cc: in function 'int main()': prog.cc:15:22: error: cannot convert 'const main()::some_struct*' 'const some_struct*' argument '1' 'bool some_function(const some_struct*)'    some_function(param) 

what (probably, depending on ownership semantics of client_operatefacerecognitiondb) want either declare some_struct , pass address function:

int main() {   const some_struct param{0};   some_function(&param); } 

...or allocate on free store:

int main() {   const some_struct* param = new some_struct{0};   some_function(param);   delete param; } 

in latter case, please consider using smart pointers if possible.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -