c++ - 为什么 c++ DLL 中的多线程在构建时会出现错误 C3867?
问题描述
我正在使用 VS2019
试图调用 DLL 中的线程。使用分离同时运行两个可执行文件
当我运行一个普通的 c++ 程序时,以下线程工作
我收到错误
错误 C3867 'myClass::runexeone':非标准语法;使用 '&' 创建指向成员 myGateway C:\Users\user\Downloads\Demo\myGateway\myplugin.cpp 的指针 21
插件头
#include <windows.h>
#include <iostream>
#include <thread>
#define MYPLUGIN_EXPORT __declspec(dllexport)
extern "C"
{
MYPLUGIN_EXPORT void WINAPI OnStart();
}
插件.cpp
#include "plugin.h"
using namespace std;
class myClass
{
public:
myClass()
{
}
~myClass()
{
}
void onStart()
{
std::thread(runexeone).detach();
std::thread(runexetwo).detach();
}
void runexeone()
{
int exerunpne = system("cmd /C \"%MY_ROOT%\\bin\\Mytest.exe\" -ORBEndpoint iiop://localhost:12345 -d");
}
void runexetwo()
{
int exeruntwo = system("cmd /C \"%MY_ROOT%\\bin\\Mytest_2.exe\" -ORBEndpoint iiop://localhost:12345 -d");
}
};
myClass& getmyclass()
{
static myClass myclass;
return myclass;
}
MYPLUGIN_EXPORT void WINAPI OnStart()
{
getmyClass().onStart();
}
解决方案
问题是这runexeone
是一个成员函数的非限定名称,并且std::thread
需要一些可执行的东西。runexeone
不是。VC++ 试图从上下文中猜测您的意思,但建议还不够。即使你已经写了&myClass::runexeone
,它仍然不会起作用,因为myClass::runexeone
还需要一个this
指针。您可以通过 make 解决后一个问题static
。
当只有一个问题时,编译器建议效果最好。
推荐阅读
- php - 为什么 TCPDF 显示?代替 Č 从 word 文件转换文本时
- python - 运行“conda update --all”会导致错误。[苹果系统]
- python - Python - 将 numpy 数组转换为 JSON
- caching - 即使我将元数据缓存控制设置为几天,Amazon S3 缓存也不起作用
- python - 从技术上讲,什么是 numpy.mgrid?
- node.js - Mongoose - 使用后更新字段的单个语句
- spring - JPA,为什么不替换本机查询中的命名参数?
- javascript - 通过多个键过滤对象数组
- javascript - 解析html文件时如何强制不发送其他请求?
- c++ - 从图中按与给定顶点共享的相邻点数的顺序打印顶点