Passing an Object and getting the return value from a thread call.

please check my code..

I want to pass a class object into a method of other class through a thread call, I tried but got the error can any one help me on this.please.

struct sample{
int status;
std::vector <std::string> a_row;
size_t column_count;
std::vector <std::string> column;
class sess {

int a;
class Gen {
static Gen* gen_obj;
static bool Gen_InstanceFlag;
static Gen* GetInstance();
sample addition(sess);

/* End of Header File */

/* Beginning of cpp File */


bool Gen::Gen_InstanceFlag=false;

Gen* Gen::GetInstance(){
Gen::gen_obj = new Gen();
Gen::Gen_InstanceFlag= true;
return gen_obj;
else {
return gen_obj;

sample addition(sess ses_obj){

sample sam;

return sam;

int main(int argc, char* argv[])
HANDLE myhandleA,myhandleB,myhandleC;

Gen* gen=Gen::GetInstance();
sess ses_obj(10);

myhandleA=(HANDLE)_beginthreadex(0, 0, gen->addition(ses_obj),(void*)0, 0, 0);

WaitForSingleObject(myhandleA, INFINITE);



return 0;

This is my code and I am getting an error like "error C2665: '_beginthreadex' : none of the 2 overloads could convert all the argument types"

Can any one suggest me who can I pass the object of sess to a funtion in a thread call and how can I get the results from the thread.

Last edited on
Your arguments to _beginthreadex() are wrong. The 3rd argument should be a pointer to your implementation of the threadproc function:

The 4th argument should be a pointer to the object you want to pass to the threadproc function.
Last edited on
You can't do that. Remember a thread is a separate/parallel unit of execution.

I think you need to pass that session thing as a parameter to something. But I'm not clear on what you're doing.

But first, can you format your code. It's really difficult to read unformatted code.
Topic archived. No new replies allowed.