1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

basic threading help

Discussion in 'C++' started by Daedalus031, Apr 6, 2012.

  1. Daedalus031

    Daedalus031 New Member

    Joined:
    Apr 6, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
    Last edited by a moderator: Apr 6, 2012
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    args is a pointer, so you must use args->id, not args.id.
     

Share This Page