这有效:
std::thread t = std::thread(printf, "%d", 1);
这不起作用:
t2 = std::thread(my_thread_func , std::ref(context));
或者
std::thread t1 = std::thread(my_thread_func , context_add);
my_thread_func 定义:
int my_thread_func(long long *context_add)
context 是一些结构 .. 我正在尝试“通过引用”
错误:
function call missing argument list;
error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments
>>> 编辑 <<<
很抱歉混淆......实际上我在 MainPage 的公共定义 my_thread_func,所以我不能使用本机类型,因此我认为值得长时间尝试并给它地址。
/* test data types, context for thread function, in .cpp (not in namespace) */
typedef struct _test_context
{
HANDLE hHandle;
unsigned int flag;
}test_context_t;
test_context_t *context;
//Do something with its member
context_add = (long long *)context;
std::thread t2 = std::thread(sem_waiting_thread, context_add);
错误:
error C3867: 'App1::MainPage::my_thread_func': function call missing argument list; use '&App1::MainPage::my_thread_func' to create a pointer to member
error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments
我的命名空间看起来像:
namespace App1
{
public ref class MainPage sealed
{
public:
MainPage();
public:
MainPage();
int my_thread_func(long long cotext);
..
};
}
<<<< EDIT 2 >>> 我现在很好奇.. 这个简单的也行不通!
void f1(int n)
{
for(int i=0; i<5; ++i) {
// Print n
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
.
.
.
int n=0;
std::thread t2(f1, n+1); (//This didn't work,same error!)
.
.
.
but this worked!
std::thread t2;
.
.
.
t2= std::thread (f1, n+1);
从这里尝试:http ://en.cppreference.com/w/cpp/thread/thread/thread