我得到了这个错误:error c2064: term没有对一个带0个参数的函数求值,但是我不明白为什么

时间:2022-06-04 01:42:02

I'm having this error: error c2064: term does not evaluate to a function taking 0 arguments. The thing is the function takes 0 arguments and I call 0 arguments, and I don't understand what's wrong.

我有这个错误:error c2064: term不计算一个带0个参数的函数。这个函数取0个参数,我调用0个参数,我不明白是怎么回事。

    RWLock* rwl = new RWLock();
    std::thread t1(&RWLock::read);

That's the call to the function. And this is the function:

这就是对函数的调用。这是函数:

    void read();

Does somebody know what the problem is? Thanks in advance!

有人知道问题出在哪里吗?提前谢谢!

2 个解决方案

#1


7  

All non-static member functions have a hidden argument, that becomes the this pointer in the member function If you want to use a non-static member function as a thread, you have to provide this hidden argument when starting the thread:

所有非静态成员函数都有一个隐藏参数,它成为成员函数中的这个指针,如果你想使用一个非静态成员函数作为线程,你必须在启动线程时提供这个隐藏参数:

std::thread t1(&RWLock::read, rwl);

#2


2  

I am pretty sure, that read() is not a static function. That is, you declared it as:

我很确定,read()不是一个静态函数。也就是说,你把它说成:

void read()

无效的read()

instead of:

而不是:

static void read()

静态孔隙read()

Non-static member function takes always one additional argument - implicit this pointer. Make read() static and it should work.

非静态成员函数总是附加一个参数——隐式这个指针。让read()静态,它应该工作。

If read() cannot be static, pass an additional argument to std::thread - a pointer to object, that read() will work on. In this case it should be rwl:

如果read()不是静态的,则将一个附加参数传递给std::thread——一个指向对象的指针,read()将继续工作。在这种情况下应该是rwl:

RWLock* rwl = new RWLock();
std::thread t1(&RWLock::read, rwl);

#1


7  

All non-static member functions have a hidden argument, that becomes the this pointer in the member function If you want to use a non-static member function as a thread, you have to provide this hidden argument when starting the thread:

所有非静态成员函数都有一个隐藏参数,它成为成员函数中的这个指针,如果你想使用一个非静态成员函数作为线程,你必须在启动线程时提供这个隐藏参数:

std::thread t1(&RWLock::read, rwl);

#2


2  

I am pretty sure, that read() is not a static function. That is, you declared it as:

我很确定,read()不是一个静态函数。也就是说,你把它说成:

void read()

无效的read()

instead of:

而不是:

static void read()

静态孔隙read()

Non-static member function takes always one additional argument - implicit this pointer. Make read() static and it should work.

非静态成员函数总是附加一个参数——隐式这个指针。让read()静态,它应该工作。

If read() cannot be static, pass an additional argument to std::thread - a pointer to object, that read() will work on. In this case it should be rwl:

如果read()不是静态的,则将一个附加参数传递给std::thread——一个指向对象的指针,read()将继续工作。在这种情况下应该是rwl:

RWLock* rwl = new RWLock();
std::thread t1(&RWLock::read, rwl);