0

While trying to use std::threads i found myself with this error.

error C2064: term does not evaluate to a function taking 1 arguments 
File: functional
Line:1152

After commenting out some lines and such i found that the error comes from the constructor.

I am also using irrlicht therefore the event variable.

Here is the declaration of the thread:

t1=new thread((&EventReceiver::KeyInput3),event);

The header of the function:

int EventReceiver::KeyInput3(const SEvent& event)

Tryed constructing it in various way but none worked. What should I do in order to get rid of the error?

taigi tanaka
  • 299
  • 1
  • 4
  • 17
  • 1
    You must pass an object of class EventReceiver to thread constructor before other args – Vasily Biryukov Jul 04 '13 at 08:23
  • possible duplicate of [C++ 11 Thread initialization with member functions compiling error](http://stackoverflow.com/questions/15434492/c-11-thread-initialization-with-member-functions-compiling-error) – juanchopanza Jul 04 '13 at 08:26

1 Answers1

3

I am guessing KeyInput is not a static member function, so you need to pass a pointer to an instance of EventReceiver first:

EventReceiver* p = ...;
std::thread t(&EventReceiver::KeyInput3, p, event);
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • 1
    Small addition: you can pass a pointer to an object, an object, a reference to an object, or a smart pointer to an object. – Pete Becker Jul 04 '13 at 14:08