954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ _beginthread

Hi,

I'm trying to create a thread for running some tasks. I copied the code from an old console application (which compiles fine), but can't figure out why it's not working now. I have searched for the error code and came across this suggestion: "Are you passing the name of a member function as a parameter accidentally?" :-O

Lift.h:

void operateIt(void *);

Lift.cpp:

void Lift::operate(int aCurrentFloor) {
	//start thread that looks at the queue and moves between floors
	_beginthread(operateIt, 5, &aCurrentFloor);
}

void Lift::operateIt(void * arg) {

	int s = *( (int*) arg );

	while(1){
   		//do magic
	}
	_endthreadex(1);
}


Errors:

IntelliSense: argument of type "void (Lift::*)(void *arg)" is incompatible with parameter of type "void (__cdecl *)(void *)"

error C3867: 'Lift::operateIt': function call missing argument list; use '&Lift::operateIt' to create a pointer to member	c:\users\alex\documents\visual studio 2010\projects\proiectsctr\proiectsctr\lift.cpp	20


Any help is appreciated.

Edit: the problem has been fixed after declaring the operateIt method static.

Buffalo101
Junior Poster
116 posts since Oct 2009
Reputation Points: 9
Solved Threads: 3
 

well, there you go. it needs to be cdecl'd. your parameters need to look like C functions. read this:
http://publib.boulder.ibm.com/infocenter/zos/v1r12/index.jsp?topic=%2Fcom.ibm.zos.r12.cbclx01%2Fcdeclkey.htm

jmichae3
Junior Poster
105 posts since Jul 2011
Reputation Points: 14
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: