I am trying to create a function that takes a variable number of matrix in parameters and multiply theses to a first one.
I can read a first one using va_arg
, but the next call of va_arg
will cause an access violation.
Here is how i declare my method :
template<class MType>
static CMatrice<MType> COperationsComplexesMatricesPassages::OCPChangementDeBase
(CMatrice<MType> & MATVecteur, unsigned int uiNbMatricesPassages,
CMatricePassage<MType> MAPMatrices...)
And here is how i call it :
COperationsComplexesMatricesPassages::OCPChangementDeBase(mat1, 2, matP1, matP2)
The exception appears on the first va_arg
of the for(...)
in the body of my method.
This is the code of my method:
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;