Joe Matt Joe Matt - 1 year ago 72
C++ Question

C++ Error 3867 with templates and multi-threading

I read some discussions on the web and on this site, furthermore I didn't manage to understand my error. I've a particular queue called BlockingQueue with a template:

template <typename T, int size>
class BlockingQueue

//constructor and other methods
void inserisci(T val) {
//do work

queue <T> fifo;
atomic<boolean> isClosed;
mutex m;

In the main, I wrote the following lines:

BlockingQueue<int, 5> bq;
int k=8;
thread t(bq.inserisci, k);
return 0;

While compiling, I obtain this error:

Error C3867: 'BlockingQueue::inserisci': function call missing
argument list; use '&BlockingQueue::inserisci' to create a
pointer to member

I read the suggestion of Visual Studio, so I tried to make a function pointer, but it does not work the same.

Answer Source

The correct code would look like following:

typedef BlockingQueue<int, 5> BQ5;
BQ5 bq;
int k=8;
thread t(std::bind(&BD5::inserisci, &bq, k));
return 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download