Thread cant ignore void datatype?

Hi guys,
I am new to the topic "Threads" but it worked so far. Sadly im struck now becuase the compiler doesnt accept void functions used with threads (for the first time and all of sudden!?)

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
31
32
33

#include <cstdlib>
#include <thread>
#include <windows.h>
#include <iostream>


const int MAX_INDEX = 2;

HANDLE hThread[MAX_INDEX];
DWORD  dwThread[MAX_INDEX];

using namespace std;

void testfunc(){
    cout << "Do something" << endl;
};


int main(int argc, char** argv) {
 
    for(int i = 0; i < MAX_INDEX; i++){
        hThread[i] = CreateThread       (NULL,
                                         0,
                                         testfunc(),       (***)
                                         NULL,
                                         0,
                                         &dwThread[i]
                                         );
    }; 
    return 0;
}


this is a sigment of my code.
Compiler says that the error occurs in line 47 (marked by ***). Leaving out the braces makes it even worse.

I'd appreciate every kind of help!
Happy easter ;)
You can't just dream up some prototype to be used as a thread entry point. You have to conform to the environment that you're using.

You're clearly using Windows, don't use CreateThread, use _beginthreadex instead.
You're calling the function instead of passing it.
Here's a discussion on something similar some years back. I hope you understand enough to find it helpful.
http://www.cplusplus.com/forum/general/27758/

I'm sure someone can help with any questions you might have.
Topic archived. No new replies allowed.