I am very new to threading and am having a small problem i just can't find the solution for. I am wanting to print out the values of args.id and args.delay inside the mythread function. however i am getting the error error "C2228: left of '.id' must have class/struct/union".
Code:
struct ThreadArgs{
int id;
int delay;
}args ;
void main(){
unsigned __stdcall mythread(void *data);
unsigned ThreadId;
int x = 5;
args.id = 2;
args.delay = 3;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, mythread, &args, 0, &ThreadId);
WaitForSingleObject(hThread, INFINITE);
//Sleep(2000);
}
unsigned __stdcall mythread(void *data)
{
Sleep(1000);
ThreadArgs *args = (ThreadArgs *) data;
cout<<args.id<<endl;
cout<<"hello world"<<endl;
return 0;
}
Thanks in advance for any help