简体   繁体   中英

Thread C++: no matching function for call to

I'm new in c++ , and I want to utilize thread to call BM class method from main class.I have main.cpp ,BM.h and BM.cpp files

some part of my code in main.cpp

string id = res->getString("nct_id");
char txt[temp_size];
char pat[5];
BM bm ;
thread Sam(&BM::search,&bm, txt, pat ,id); // use thread calls class method

BM.h

void search( char *txt,  char *pat , string id);

BM.cpp

void BM::search( char *txt,  char *pat ,string id)

I have error:

No matching function for call to
'std::thread::thread(void (BM::*)(char*, char*, std::string), BM*, char [(((sizetype)(((ssizetype)temp_size) + -1)) + 1)], char [5], std::string&)'

please help me

thank you

This is because you are using a non-standard language extension, namely, variable-length arrays (VLAs). These arrays don't work well with templates. It is recommended to ditch all character arrays and all VLAs, and use std:string and std::vector throughout.

If you cannot, use this simple workaround:

thread Sam(&BM::search,&bm, &txt[0], pat ,id); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM