Function reference issue
I the following error when compiling the below code... Note this worked fine until I created the header and added the functions to the pkg class.
'&' : illegal operation on bound member function expression
The error refers to the call to create a thread running functionX.
Any ideas? I did try CreateThread(NULL,0,&pkg::functionX,NULL, 0, 0); but no joy.
Thanks!
pkg.h
1 2 3 4 5 6 7 8 9 10 11
|
#include "stdafx.h"
#include <windows.h>
class Pkg
{
public :
void functionY();
DWORD WINAPI functionX(void*);
};
|
pkg.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include "stdafx.h"
#include "Pkg.h"
DWORD WINAPI functionX(void*);
DWORD WINAPI Pkg::functionX(void*){
return 0;
}
void Pkg::functionY() {
CreateThread(NULL,0,&functionX,NULL, 0, 0);
}
|
The cause is not that you moved declaration in header. It is due to the function becoming a member of a class.
declaring a function WINAPI would make it a "C" function read here
http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
For passing a class member to CreateThread would require something like
1 2 3 4
|
void Pkg::functionY() {
auto threadFunc = std::bind(&Pkg::functionX, this, std::placeholders::_1)
CreateThread(NULL,0,threadFunc ,NULL, 0, 0);
}
|
Topic archived. No new replies allowed.