dimanche 28 décembre 2014

Function with multiple structure arguments in a multithreaded application using c++11

I get an error doing this:



struct S1
{
int * A;
double* B;
std::string* C;
} S1;

struct S2
{
int* D;
char* E[10];
float F;
} S2;

struct SBoth
{
S1* data1;
S2* data2;
} SBoth;

bool Afunction(void* sdata1, void* sdata2)
{
S1* var1 = (S1*)(sdata1);
S2* var2= (S2*)(sdata2)
do something with sdata and sdata, like displaying their content
}

int main()
{
:
:

S1 mydata1;
S2 mydata2;

std::thread thrd(Afunction,(void*)&mydata1,(void*)&mydata2);

thrd.join();
return 0;

}


i'm suspecting a need for copy constructor , but i am not sure if that is necessary for structures. of course i have other threads to run, but what is an elegant way of doing this...?


Aucun commentaire:

Enregistrer un commentaire