我正在嘗試編譯一個程式,但它不斷出現錯誤;我搜索了論壇,我認為這與傳遞參考有關,但我找不到我出錯的地方。
這是代碼的摘錄:
#include <iostream>
#include <thread>
using namespace std;
const int N = 512;
const int N_BUSC = 8;
using VectInt = int[N];
void coord (VectInt v, bool& lectura, bool acabados[N_BUSC], int resultados[N_BUSC]);
int main(int argc, char *argv[]){
bool leido = false;
VectInt v;
int acabados [N_BUSC], resultados [N_BUSC];
...
thread coordinacion (&coord, v, std::ref(leido), acabados, resultados);
...
}
它一直顯示的錯誤是:
/usr/include/c /9/thread: In instantiation of ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int*, bool&, bool*, int*); _Args = {int (&)[512], std::reference_wrapper<bool>, int (&)[8], int (&)[8]}; <template-parameter-1-3> = void]’:
ej1.cpp:43:74: required from here
/usr/include/c /9/thread:120:44: error: static assertion failed: std::thread arguments must be invocable after conversion to rvalues
120 | typename decay<_Args>::type...>::value,
| ^~~~~
/usr/include/c /9/thread: In instantiation of ‘struct std::thread::_Invoker<std::tuple<void (*)(int*, bool&, bool*, int*), int*, std::reference_wrapper<bool>, int*, int*> >’:
/usr/include/c /9/thread:131:22: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int*, bool&, bool*, int*); _Args = {int (&)[512], std::reference_wrapper<bool>, int (&)[8], int (&)[8]}; <template-parameter-1-3> = void]’
ej1.cpp:43:74: required from here
/usr/include/c /9/thread:243:4: error: no type named ‘type’ in ‘struct std::thread::_Invoker<std::tuple<void (*)(int*, bool&, bool*, int*), int*, std::reference_wrapper<bool>, int*, int*> >::__result<std::tuple<void (*)(int*, bool&, bool*, int*), int*, std::reference_wrapper<bool>, int*, int*> >’
243 | _M_invoke(_Index_tuple<_Ind...>)
| ^~~~~~~~~
/usr/include/c /9/thread:247:2: error: no type named ‘type’ in ‘struct std::thread::_Invoker<std::tuple<void (*)(int*, bool&, bool*, int*), int*, std::reference_wrapper<bool>, int*, int*> >::__result<std::tuple<void (*)(int*, bool&, bool*, int*), int*, std::reference_wrapper<bool>, int*, int*> >’
247 | operator()()
| ^~~~~~~~
先感謝您。
uj5u.com熱心網友回復:
您傳遞給的引數coord與其簽名不匹配。
void coord (VectInt v, bool& lectura, bool acabados[N_BUSC], int resultados[N_BUSC])
^^^^
int如果您想將一個陣列傳遞int給該函式,則應該是這樣- 或者您應該將一個陣列傳遞bool給它:
bool acabados [N_BUSC]; // not int[N_BUSC]
int resultados [N_BUSC];
thread coordinacion (&coord, v, std::ref(leido), acabados, resultados);
演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340737.html
上一篇:用一個回圈列出兩個骰子的排列
