Unklare Compilerfehlermeldung
-
So sieht meine Klasse aus:
class Fourier { public: ... Fourier( int K_, double* Xtrain_, int XTrainLength_, double* Xtest_, int XTestLength_, double* L_, double* centers_, int centersLength_, double* alphas_, double sigma_ ); ... }; ... Fourier::Fourier( int K_, double* Xtrain_, int XTrainLength_, double* Xtest_, int XTestLength_, double* L_, double* centers_, int centersLength_, double* alphas_, double sigma_ ) { ... }Und so erzeuge ich ein Objekt:
Fourier fourier( K, Xtrain, XtrainLength, Xtest, XtestLength, L, centers, centersLength, alphas, sigma );Wenn ich es kompiliere erhalte ich folgende Fehlermeldung:
make
g++ -fPIC -ansi -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I/Applications/MATLAB_R2009b.app/extern/include -c FourierDifference7D.cpp
FourierDifference7D.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
FourierDifference7D.cpp:180: error: no matching function for call to ‘Fourier::Fourier(int&, double*&, int&, double*&, int&, double&, double*&, int&, double*&, double&)’
FourierDifference7D.cpp:39: note: candidates are: Fourier::Fourier(int, double*, int, double*, int, double*, double*, int, double*, double)
FourierDifference7D.cpp:12: note: Fourier::Fourier(const Fourier&)
make: *** [FourierDifference7D.o] Error 1Was mache ich falsch?
-
Da stimmen die Typen nicht ganz. Zeig mal die Deklaration der Variablen, die du übergibst.
-
Die Metode die so ein Fourier Objekt erzeugt sieht wie folgt aus (es handelt sich dabei um ein Plugin für das Programm matlab):
void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] ) { if( nrhs < 7 ) mexErrMsgTxt("[f,g] = FourierDifference7D( Xtrain, Xtest, centers, L, sigma, alpha, K )\n"); const mwSize* dimsCount1 = mxGetDimensions(prhs[0]); if( dimsCount1[1] != 7 || (dimsCount1[0] < dimsCount1[1])) mexErrMsgTxt("First argument (Xtrain) must be a Nx7 data matrix.\n"); double *Xtrain = mxGetPr(prhs[0]); int XtrainLength = dimsCount1[0]; const mwSize* dimsCount2 = mxGetDimensions(prhs[1]); if( dimsCount2[1] != 7 || (dimsCount2[0] < dimsCount2[1])) mexErrMsgTxt("Second argument (Xtest) must be a Nx7 data matrix.\n"); double *Xtest = mxGetPr(prhs[1]); int XtestLength = dimsCount2[0]; const mwSize* dimsCount3 = mxGetDimensions(prhs[2]); if( dimsCount3[1] != 7 || (dimsCount3[0] < dimsCount3[1])) mexErrMsgTxt("Third argument (centers) must be a Nx7 data matrix.\n"); double *centers = mxGetPr(prhs[2]); int centersLength = dimsCount3[1]; const mwSize* dimsCount4 = mxGetDimensions(prhs[3]); if( dimsCount4[0] != 1 || dimsCount4[1] != 7 ) mexErrMsgTxt("Fourth argument (L) must be a 1x7 vector of period lengths.\n"); double L = *mxGetPr(prhs[3]); const mwSize* dimsCount5 = mxGetDimensions(prhs[4]); if( dimsCount5[0] != 1 || dimsCount5[1] != 1 ) mexErrMsgTxt("Fifth argument (sigma) must be a scalar.\n"); double sigma = *(mxGetPr(prhs[4])); const mwSize* dimsCount6 = mxGetDimensions(prhs[5]); if( !( dimsCount6[0] == centersLength || dimsCount6[1] == centersLength ) ) mexErrMsgTxt("Sixth argument (alpha) must be the same length as centers.\n"); double *alphas = mxGetPr(prhs[5]); const mwSize* dimsCount7 = mxGetDimensions(prhs[6]); if( dimsCount7[0] != 1 || dimsCount7[1] != 1 ) mexErrMsgTxt("Eighth argument (K) must be a scalar.\n"); int K = (int) *(mxGetPr(prhs[6])); if( nlhs < 1 ) mexErrMsgTxt("Return value is missing.\n[f,g] = FourierDifference7D( Xtrain, Xtest, centers, L, sigma, alpha, K )\n"); plhs[0] = mxCreateDoubleScalar(0.0); double* f = mxGetPr(plhs[0]); Fourier fourier( K, Xtrain, XtrainLength, Xtest, XtestLength, L, centers, centersLength, alphas, sigma ); ...Die Methde mxGetPr(prhs[6]) liefert immer einen Pointer vom Typ Double zurück (http://www.mathworks.com/help/techdoc/apiref/mxgetpr.html)
-
Hoppla hab den Fehler gefunden. Ich hatte ausversehen
double L = *mxGetPr(prhs[3]);
geschrieben es muss aber
double* L = mxGetPr(prhs[3]);
lauten.
Vielen Dank für Eure Hilfe.
-
Wenn du jetzt noch die Fehlermeldung verstehst ist alles gut.
Die besagt nämlich ziemlich genau was das Problem ist.
-
Dass du bei der Fehlermeldung nicht durchblickst hat ne ganz einfache Ursache, nämlich dass du eine widerlich lange Parameterliste hast. Das sieht aus, als könnte man an einigen Stellen Pointer+Längenangaben durch Container ersetzen...