Problem using boost thread library

I am trying to execute function from class in other thread, but I get error:
'CFTP::_getfile': function call missing argument list; use '&CFTP::_getfile' to create a pointer to member

What I am trying to do:
1
2
3
4
boost::thread	thread ( _getfile );

// _getfile function
void	CFTP::_getfile	( )


I tried to do what the error says, but it doesn't solve problem, I gain other error. I need to have this function in class, because it has some CFTP variables. How can I solve this problem?
You could use your CFTP class as a functor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//CFTP.h

class CFTP
{
     private:
          int private_var1; //I don't know what members this class has. These are just examples
          bool private_var2;

     public:
          char public_var1;
          long public_var2;

          CFTP(int i, bool b, char c, long l)
          {
               private_var1 = i;
               private_var2 = b;
               public_var1 = c;
               public_var2 = l;
          }

          void _getfile()
          {
               //get the file!
          }

          void operator()() //this is the method that boost will call when the thread starts
          {
               _getfile();
          }
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//main.cpp
#include <boost/thread.hpp> 
#include "CFTP.h"

int main()
{
     CFTP cftpInstance(1, true, 'c', 100);

     boost::thread aThread(cftpInstance); //now, CFTP::operator()() will be called

     //wait for the thread
     aThread.join();

     return 0;
}
Thanks. But if I have another function in the same class to thread, whats then?
You can use inheritance.

1
2
3
4
5
6
7
8
class CFTPWorker1 : public CFTP
{
     public:
          void operator()()
          {
               _getfile();
          }
};


1
2
3
4
5
6
7
8
class CFTPWorker2 : public CFTP
{
    public:
          void operator()()
          {
               //call another function
          }
};
thank you.
Topic archived. No new replies allowed.