【发布时间】:2018-10-08 17:01:48
【问题描述】:
首先,我是一个完整的 C++ 新手。我正在尝试使用一些结构数组(包括 2D 结构)作为参数调用函数,但出现以下错误:
没有用于调用“函数”的匹配函数:候选函数不可行:第一个参数没有从“struct _psoParticle [particleQnty][2]”到“_psoParticle (&)[][2]”的已知转换
我的结构(假设 material = 1 和 period = 10):
struct unit{
int inventory[material][period];
int consumption[material][period];
int replenishment[material][period];
int planned[material][period];
int accPlanned[material][period];
int demandPull[material][period];
int costPenalty[material][period];
bool delivery[material][period];
int leadtime;
int inventoryControl[material][period];
double bufferSize[material][period];
double bufferLevel[material][period];
double bufferMgmt[material][period];
const double lbGamma{-100.0};
const double ubGamma{100.0};
};
struct _psoParticle{
double positionBest;
double velocityBest;
long pbest;
};
在 main 中初始化数据:
struct unit CareUnit[2]{};
struct unit centralStore{};
struct _psoParticle psoParticle_CareUnit[10][2];
struct _psoParticle psoParticle_CentralStore[10];
int totalConsumption[material]{}, totalInventory{}, totalLateness{};
int particleQnty{10};
int x[particleQnty]{};
函数头:
int dbr(_psoParticle (&pso_CareUnit)[][2], _psoParticle (&pso_CentralStore)[],
int particle, unit (&CareUnit)[], unit ¢ralStore,
int (&totalConsumption)[1], int &totalInventory, int &totalLateness);
继续主线:
for (int i = 0; i < particleQnty; ++i)
x[i] = dbr(psoParticle_CareUnit, psoParticle_CentralStore, i, CareUnit,
centralStore, totalConsumption, totalInventory, totalLateness);
然后弹出错误信息。
关于我做错了什么有什么想法吗?
谢谢!
【问题讨论】:
-
实际的错误信息是什么?
-
@melpomene:没有匹配的函数调用'function'
-
不,实际的完整错误消息。
-
哦!我以前没看到!是 1. 候选函数不可行:需要单个参数“pso_CareUnit”,但提供了 8 个参数
-
这还不是完整的信息。而你错过了minimal reproducible example。
标签: c++ arrays function struct compiler-errors