在类中创建线程会导致错误C2664
Making a thread inside a class give me error C2664
让我把你放在上下文中。我正在使用Qt Creator制作一个聊天框。我对C++还很陌生,所以这是一个挑战。我想使用std::thread
创建一个线程。这是我写的代码:
window.h
class Window: public QWidget
{
Q_OBJECT
public:
Window();
public slots:
void Config();
private:
void ListenToClients(Server server);
//member...
};
window.cpp
Window::Window(): QWidget()
{
//not important code...
do
{
//nothing
}while(config.getLaunch() == false);
Server myServer(config.getPort(), config.getBroadcast());
std::thread serverThread(&Window::ListenToClients, this, myServer);
}
void Window::Config()
{
config.exec();
}
void Window::ListenToClients(Server server)
{
for(int i = 0; i < 100; i++)
{
server.ListenNewConnections();
}
}
所以我得到了这个错误:错误:C2664:'std::tuple<void (__cdecl Window::* )(Server),Window *,Server>::tuple(std::tuple<void (__cdecl Window::* )(Server),Window *,Server> &&)'ÿ: imossible to convert argument 1 of 'void (__cdecl Window::* )(Server)' in 'std::allocator_arg_t'
我不知道为什么,也不知道这意味着什么。我搜索了一下,但似乎没有人出现过这样的错误。所以,我指望你们所有人。
"std::allocater_arg_t"听起来像是您的构造函数参与其中,因为它正在分配一些东西:
Window::Window(): QWidget()
无效,您已经在类分离中继承了QWidget,因此QWidget的构造函数被隐式调用。CCD_ 4就足够了。
另外:我不知道public slots:
应该是什么意思。您可以完全省略它,因为您已经有了上面的public:
限定符。
相关文章:
- 使用解算器SparseLU并获得错误C2664
- VS 2017 错误 C2664 地图插入尝试
- 使用自定义对象声明shared_ptr数组时出现错误 C2664
- 编译器错误 C2664 使用 std::map 和自定义类作为其值
- 如何在 VC++ 中通过引用传递另一个对象的方法(错误 C2664)
- 在C++中构造模板函数时出现编译错误 C2664 和 C2440
- 了解错误 C2664:无法转换参数 1
- 错误 C2664:无法从'NvPhysicalGpuHandle'转换参数 1
- 错误 C2664 和 E0167 被难倒
- 尝试创建unique_ptr时出现错误 C2664
- 错误 C2664:"errno_t wcstombs_s(size_t *,字符 *,size_t,常量 wchar_t *,size_t)":无法转换参数 4
- 错误C2664:无法转换参数错误
- 在集合中转换为小写 C++ 错误 C2664
- 错误 C2664:无法将参数 1 从 'int' 转换为 'int []'
- 将互斥锁数组传递给函数时出现错误 C2664
- 错误 C2664:"发送":无法将参数 2 从"服务器问候语"转换为"常量字符 *"
- 错误C2664:无法转换参数(指纹传感器检测)
- C++ 错误 1 错误 C2664 传递数组指针
- 错误 C2664:'CComboBox::InsertString':无法将参数 2 从 'const char [4]' 转换为 'LPCTSTR'
- 创建面向对象的链表时出现编译问题(编译器错误C2664)