passing multiple vectors to function by reference (using structure)
Posted
by madman
on Stack Overflow
See other posts from Stack Overflow
or by madman
Published on 2010-03-30T16:56:50Z
Indexed on
2010/03/30
17:13 UTC
Read the original article
Hit count: 400
Hi StackOverflow,
Can someone tell me the correct way of passing multiple vectors to a function that can take only a single argument? (specifically for pthread_create (..) function)
I tried the following but it does not seem to work :-(
First, I created the following structure
struct ip2
{
void* obj;
int dim;
int n_s;
vector<vector<vector<double> > > *wlist;
vector<int> *nrsv;
struct model *pModel;
};
The threads that I have created actually needs all these parameters. Since im using pthreads_create I put all this in a structure and then passed the pointer to the structure as an argument to pthread_create (as shown).
some_fxn()
{
//some code
struct ip2 ip;
ip.obj=(void*) this;
ip.n_s=n_s;
ip.wlist=&wlist;
ip.nrsv=&nrsv;
ip.pModel=pModel;
ip.dim=dim;
pthread_create(&callThd1[lcntr], &attr1, &Cls::Entry, (void*) &ip);
}
The Entry method looks something like this.
void* Cls::Entry(void *ip)
{
struct ip2 *x;
x = (struct ip2 *)ip;
(reinterpret_cast<Cls1 *>(x->obj))->Run(x->dim,x->n_s, x->wlist, x->nrsv, x->pModel);
}
The Run method looks something like this.
void Run(int dim, int n_c, vector<vector<vector<double> > > *wlist, vector<int> *nrsv, struct model* pModel )
{
//some code
for(int k = 0; k < n_c; ++k)
{
//some code
end = index + nrsv[k];
//some code
}
I get the following error when I try to compile the program.
error: no match for ‘operator+’ in ‘index + *(((std::vector<int, std::allocator<int> >*)(((unsigned int)k) * 12u)) + nrsv)’
Can someone tell me how to do it the right way.
Madhavan
© Stack Overflow or respective owner