如何初始化DefenseThread以便它将开始执行Defend()?我已经看过很多关于如何从没有标题的.cpp文件中执行此操作的示例,但是没有。
void CommandDefend :: DefendStart()
获取以下错误:
'&安培;'需要I值
部首:
#pragma once
#include <thread>
class CommandDefend : public ICommand
{
public:
CommandDefend();
~CommandDefend();
private:
thread* DefenseThread;
/// <summary>
/// Starts the commands execution.
/// </summary>
void DefendStart();
/// <summary>
/// Does the actual defending.
/// </summary>
void Defend();
};
CPP:
#include "stdafx.h"
#include "CommandDefend.h"
void CommandDefend::DefendStart()
{//ERROR HERE!!!!!!
DefenseThread = new thread(&CommandDefend::Defend);
}
void CommandDefend::Defend()
{
}
答案 0 :(得分:1)
如果您更换
$parameters = ['json' => [
'roles' => $roles
]
];
$res = $client->request($method, $discord->baseUrl.$url, [
'headers' => [
'content-type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bot key'
],
"json" => $parameters["json"]
]);
带
DefenseThread = new thread(&CommandDefend::Defend);
它应该工作,因为它是我初始化类型DefenseThread = new thread(&CommandDefend::Defend, this);
的类成员的方式(虽然它们不是指针)。