How to pass same instance of object in two function in c++

I need to send same instance of object of a class in two function (Main function and thread function)

The class is something like this:

1
2
3
4
5
6
7
8
9
10
11
//The class need to have constructor. 
Class ABC
{
public:
    DWORD *IdG;

   ABC(int number)
   { 
       IdG = new DWORD[number];
   }
}obj(32);


The obj(32) is called in following two function. Function F1 is called using thread in main function.

1
2
3
4
5
6
7
8
9
10
void F1()
{
   obj.test;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
     obj.test1;
    _beginthread(F1,0,(void*)number);
}


The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.

If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.

How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.
Pass obj as an argument to F1. Since F1 is your thread entry point, this is a little more tricky since you must work with a void pointer. The strategy is to pass a pointer to your object, then just cast it to the correct pointer type inside the thread function (since you know what type you are passing to it).
Topic archived. No new replies allowed.