user2968192
user2968192

Reputation: 21

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

Upvotes: 0

Views: 209

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

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); 

Upvotes: 2

Related Questions