[ale] OT: dummy C++/threads question
John Mills
johnmills at speakeasy.net
Wed Jul 23 12:50:14 EDT 2003
Christopher, ALErs -
On Wed, 23 Jul 2003, Christopher Fowler wrote:
> Remove the '&' and that should pass the function through. What
> are the errors you are getting?
Declaration of member to be started:
void * CCamera::RunOneCamera(void * lpParam)
{ blah }
Function to start the thread:
...
idCThread = pthread_create(&(cThread[Ci]), NULL,
CCamera::RunOneCamera, &cParm[Ci]);
...
Compiler (g++) says:
...
Camera.cpp: In method `int CCamera::ServeACamera (int)':
Camera.cpp:165: assuming & on `CCamera::RunOneCamera'
Camera.cpp:165: cannot convert `void *(CCamera::*) (void *)' to `void
*(*) (void *)' for argument `3' to `pthread_create (pthread_t *, const
pthread_attr_t *, void *(*) (void *), void *)'
...
If I put in the '&' it still refuses the type on the same basis.
If I make 'void *RunOneCamera(void*)' a local function instead of a class
member (and drop it from the member list in Camera.h), the argument is
passed successfully - with or without the '&' (which I think _is_ needed).
Stroustrup(2nd ed) gives an example (5.4.5, pg.166), but I can't seem to
get it together.
Thanks for any ideas.
> > I have a C++ class with a member function, say:
> >
> > void * CMyClass::MyFunction(void * myArgs) {blah}
> >
> > I want to this function to be executed in a thread started by another
> > member of the same class:
> >
> > fnType CMyClass::MyManager()
> > {
> > ...
> > pthread_create(&someInt, NULL, &CMyclass::MyFunction, &someStruct);
> > // can't get this right-->> ^^^^^^^^^^^^^^^^^^^^^
> > }
John Mills
john.m.mills at alum.mit.edu
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list