【发布时间】:2019-06-01 10:45:06
【问题描述】:
我正在尝试创建一个函数,该函数在参数中采用可变数量的矩阵并将这些矩阵乘以第一个。
我可以使用va_arg 读取第一个,但下一次调用va_arg 会导致访问冲突。
这是我声明我的方法的方式:
template<class MType>
static CMatrice<MType> COperationsComplexesMatricesPassages::OCPChangementDeBase
(CMatrice<MType> & MATVecteur, unsigned int uiNbMatricesPassages,
CMatricePassage<MType> MAPMatrices...)
我是这样称呼它的:
COperationsComplexesMatricesPassages::OCPChangementDeBase(mat1, 2, matP1, matP2)
异常出现在我的方法主体中for(...) 的第一个va_arg 上。
这是我的方法的代码:
unsigned int uiIndice;
unsigned int uiBaseArriveePrecedente;
va_list args;
va_start(args, MAPMatrices);
CMatrice<MType> MATResult(MATVecteur);
CMatricePassage<MType> MAPMatricePass = va_arg(args, CMatricePassage<MType>);
MATResult = MATResult * MAPMatricePass;
uiBaseArriveePrecedente = MAPMatricePass.MAPGetBaseArrivee();
for (uiIndice = 1; uiIndice < uiNbMatricesPassages; uiIndice++) {
CMatricePassage<MType> MAPMatricePass2 = va_arg(args, CMatricePassage<MType>);
if (uiBaseArriveePrecedente != MAPMatricePass2.MAPGetBaseDepart()) {
CException EXCError(EXC_ChangementImpossible);
throw EXCError;
}
uiBaseArriveePrecedente = MAPMatricePass2.MAPGetBaseArrivee();
MATResult = MATResult * MAPMatricePass2;
}
return MATResult;
【问题讨论】:
标签: c++ templates variadic-functions variadic